Tuesday, February 28, 2012

How can I hide the "Send notification email to contact" checkbox in Case object?

Cases > Page Layouts
Edit Page layout, on the top most you can find a button called 'Layout Properties'. clicking on that will give you the ability to show/hide the send "Email Notification Checkbox"
Same way you can show/hide the "Case Assignment Checkbox" in Edit page.
Fyi, checkbox need to selected default means, need to select both Checkbox "Show on edit page" and "Select by default".
if you select "Select by default" checkbox alone its not working.

Get values of form field in javascript from a visualforce page

<apex:page >
    <script language="javascript">
        function getCheckBoxValue()
        {
            alert(document.getElementById('{!$Component.myForm.pb1.pbs1.checkbox1}').checked);   
        }
    </script>
    <apex:form id="myForm">
        <apex:pageblock id="pb1">
            <apex:pageblockSection id="pbs1">
                <apex:inputCheckbox id="checkbox1" label="Check Me" onclick="javascript&colon;getCheckBoxValue();"></apex:inputCheckbox>
            </apex:pageblockSection>
        </apex:pageblock>
    </apex:form>
</apex:page>

how can we use javascripts in visualforce pages?

<apex:page sidebar="false" showheader="false">
<script>
function changeFontColor(Id,textValue) {
 if(Id.checked) {
  document.getElementById(textValue).style.fontWeight = "bold";
  document.getElementById(textValue).style.color= "green";
 } else {
  document.getElementById(textValue).style.fontWeight = "Normal";
  document.getElementById(textValue).style.color= "black";
 }
}
</script>
 <apex:outputPanel layout="block">
  <label for="checkbox">Click this box</label>
  <input type="checkbox" id="check1" onclick="changeFontColor(this,'{!$Component.theOutputPanel}');" />
 </apex:outputPanel>
 <apex:outputPanel id="theOutputPanel" layout="block">Change Font Color and Font Weight</apex:outputPanel>
</apex:page>

Demo Link : http://sfdevforce-developer-edition.na12.force.com/JSinVF

Monday, February 27, 2012

Customer Portal - Use VisualForce Page as Home Page

You can go to Setup > Create > Tabs and create a new VisualForce tab with the VF page that you want to use as the home page.

Then go to your Customer Portal > Customize Portal Tabs > and add your new VisualForce tab to the Selected tabs and set that tab as the Default Landing Tab.


Synchronous and Asynchronous Calls with the AJAX Toolkit

The AJAX Toolkit allows you to issue synchronous or asynchronous calls. Asynchronous calls allow the client side process to continue, waiting for a call back from the server. To issue an asynchronous call, you must include an additional parameter with the API call, referred to as a callback function. Once the result is ready, the server invokes the callback method with the result.

Synchronous syntax:

sforce.connection.method("arg1","arg2", ...);
For example:

sforce.connection.login("MyName@MyOrg.com","myPassword1");
 
Asynchronous syntax:

method("arg1","arg2", ..., callback_method);
For example:

var callback = {onSuccess: handleSuccess, onFailure: handleFailure};
function handleSuccess(result) {}
function handleFailure(error) {}
sforce.connection.query("Select name from Account", callback);

VF Page:
<apex:page>
<head>
<script src="/soap/ajax/20.0/connection.js" type="text/javascript"></script>
<script>
window.onload = function() {
var AccountOutput = document.getElementById("AccountOutput");
var StartTime = new Date().getTime()
try {
 sforce.connection.sessionId = "{!$Api.Session_ID}"; //Used for Session out
 var queryResult = sforce.connection.query("Select Name, Industry From Account where Name!=null");
 AccountResults(queryResult, AccountOutput, StartTime);
} catch(error) {
 queryFailed(error, AccountOutput);
}
}
//if failed for Query
function queryFailed(error, out) {
 out.innerHTML = "<font color=red>An error has occurred:</font> <p>" + error;
}
//if gets Results and pass to 'out' variable
function AccountResults(queryResult, out, startTime) {
 var timeTaken = new Date().getTime() - startTime;
 if (queryResult.size > 0) {
  var AccountOutput = "";
  var records = queryResult.getArray('records');
  for (var i = 0; i <records.length; i++) {
  var account = records[i];
   AccountOutput += account.Name + "   [Industry -   "+   account.Industry + "  ]<BR>";
  }
  out.innerHTML = AccountOutput + "<BR> query complexed in: " + timeTaken + " ms.";
 } else {
  out.innerHTML = "No records matched.";
 }
}
</script>
</head>
<body>
<div id="AccountOutput">
</div>
</body>
</apex:page>

Upsert

Upsert:
Syntax:
UpsertResult[] ur= connection.upsert(String externalIdFieldName, sObject[] sObjects);

    Upsert is creates new records and updates existing records; uses a custom field to determine the presence of existing records. Use upsert() instead of create() to avoid creating unwanted duplicate records You can process records for the one more than object type in an create() or update() call, but all records must have same object type in an upsert() call.
   Upsert is merging of the words insert and update. This call is available for the objects if the object has an external ID field or a field with the idLookup field property.

Select update/create:
    * If external ID is not matched, then a new record is created.
    * If external ID is matched once, then the existing record is updated.
    * If external ID is matched multiple times, then an error is reported.
    * When batch updating multiple records where the external ID is the same for two or more records in your batch call, those records will be marked as errors in the UpsertResult file. The records will be neither created nor updated.
Sample Code:
lstAccount = [select Id, Name, Team__c, Phone, from  Account];
if(lstAccount.size() == 0) {
 AccountObj = new Account();
 AccountObj.Name = 'SFDC';
 AccountObj.Team__c = 'Engineering';
 AccountObj.Phone = '04445658985';
} else {
 AccountObj = lstAccount[0];
}
try {
 upsert AccountObj;
}
catch (DMLException e) {
 system.debug('DMLException :' + e);
 ApexPages.addMessage(new ApexPages.Message(ApexPages.severity.ERROR,'ERROR While Creating/Updating Account'));
}

Thursday, February 23, 2012

Difference between Force.com and Salesforce.com

Force.com is a platform where you can develop your own application.
Salesforce.com is Sales(CRM) and Service applications which were developed and running on the Force.com Platform.

Force.com is based on the concept of Platform as a Service or commonly known as PAAS where as Salesforce.com is based on the concept of Application as a Service.

The developed applications will run on the force.com always as a multitenent architecture method.

Simply you can identify Forc.com is where you can access and customize your datamodel, bussiness logic and UserInterface. But in case of salesforce.com you can access the sales(CRM) Application with all the developed data model, Business logic and UserInterface. Then you can customize your application funtionality, since it is running on the force.com platform.

So, we can say Salesforce.com is an application build by SFDC on force.com platform and has been made available to people for use at a per month per license pricing.

As a rule of thumb: Force.com platform license is three times cheaper then the Salesforce.com license but takes three times of effort and time to build any functionality which is billed in Salesforce.com application.
Force.com is the platform because of which SFDC says sky is the limit for developing any application.

Tuesday, February 21, 2012

Pagination In Salesforce

Pagination using Visualforce and Apex Class


Apex Class : 
public class accountPaginationCls
{
    public Integer noOfRecordPerPage {get;set;}
    public Integer selectedPage {get;set;}
    public Map<Integer, List<Account >> mapAccounts{get;set;}
    public List<selectoption> pagesOptions {get;set;}
    public accountPaginationCls(ApexPages.StandardController controller) {
        mapAccounts =new Map<Integer, List<Account >> ();
        noOfRecordPerPage = 5;
        selectedPage = 1;
        List<Account> listAccounts = [select Name from Account order by Name asc];
        if(listAccounts.size()>0){
            pagesOptions = new List<SelectOption>();
            integer total_no_of_pages = listAccounts.size()/noOfRecordPerPage;                
            if(math.mod(listAccounts.size(),noOfRecordPerPage) > 0){
               total_no_of_pages = total_no_of_pages +1;
            }
            integer pageStartValue = 0;
            integer pageEndValue = noOfRecordPerPage;
          for(integer i = 0; i<total_no_of_pages ; i++){
                integer counter = i+1;
                pagesOptions.add(new SelectOption(counter+'',counter +''));
                List<Account> AccountList = new List<Account>();
               for(integer j = pageStartValue ; j< pageEndValue; j++){
                        try{
                            AccountList.add(listAccounts[j]);
                        }
                        catch(Exception e) {
                        }
                }
                pageStartValue = pageEndValue;
                pageEndValue = noOfRecordPerPage*(i+2);
            mapAccounts.put(counter,AccountList);
           }
        }
  } 
    public void nextPage(){}
}



Visualforce Page :
<apex:page standardController="Account" extensions="accountPaginationCls" sidebar="false" showHeader="false">
 <apex:form id="frm">
   <apex:pageBlock title="Pagination" >
       <apex:pageblockSection columns="1">
            <apex:repeat value="{!mapAccounts[selectedPage]}" var="a">
                <apex:outputLabel value="{!a.name}"></apex:outputLabel>
            </apex:repeat>
           <apex:selectList value="{!selectedPage}" size="1" multiselect="false">
               <apex:SelectOptions value="{!pagesOptions}"></apex:SelectOptions>
            <apex:actionSupport event="onchange" action="{!nextPage}" reRender="frm" />
            </apex:selectList> 
      </apex:pageblockSection>
  </apex:pageBlock>
 </apex:form> 
</apex:page>



Demo : http://sfdevforce-developer-edition.na12.force.com/

Tuesday, February 14, 2012

Different Types of Salesforce.com Sandbox

There are Two kind of salesforce.com environments:

* Production Environment
* Sandbox Environment

Production is an environment where the actual users work with the actual data and is maintained by Administrators.
Sandbox is  an environment shared by Salesforce.com for the testing and the development purpose and is mostly used by Developers and Testers.

Migration from sandbox to production environment can happen via Eclipse tool or SFDC Change sets. Eclipse tool is a much more recommended approach.
There are three kind of Sandboxes in SFDC and the difference lies in the limit of Data Storage

Developer Sandbox
: This is the most basic sandbox provided by SFDC. This comes as free and can even be created by anyone who wants to have Look and Feel of SFDC. It can store 10 MB of data and can be refreshed everyday ( Feature of Winter'11 Release ).This sandbox can not be created from production environment.

Config only Sandbox: This is a paid sandbox and cost around 10% of production environment. This is mostly used when system needs to be tested with good chunk of data. This sandbox can be created directly from the production environment and can be refreshed everyday. This Sandbox has the 500MB Data Limit.

Full Copy Sandbox: This is also a paid sandbox and cost around 15% to 20% of production environment. The Full copy sandbox of SFDC is exact replica of the production environment and even stores the actual business data. This sandbox can be created from the SFDC production environment and can be refreshed after every 28 days. The Full Copy Sandbox has same Data Limit as the Production environment has.

The Record Id's are similar only in the case of Full Copy Sandbox and Production Environment as Full Copy Sandbox is replica of the Production Environment. CON 201 Certification Question, DEV 401 Certification Question

It's always advisable to negotiate for these Sandbox at the time of buying salesforce.com licenses as one gets different no. and types of sandboxes depending on the edition of salesforce selected.

Monday, February 13, 2012

VisualForce Reports: Excel, Word, PDF, CSV

Excel:
For this report, creating an HTML table will work to render the data in its appropriate columns and rows. You may also use apex:pageBlockTable, apex:repeat, apex:dataTable, etc.

The "#report.xls" tagged at the end of the contentType string will be the name of your file. Also, you have to set cache="true" for IE support.


<apex:page controller="ReportController" contentType="application/vnd.ms-excel#report.xls" cache="true">

Word:
Same as the Excel file, the "#report.doc" tagged at the end of the contentType string will be the name of your file. Again, you have to set cache="true" for IE support.

<apex:page controller="ReportController" contentType="application/msword#report.doc" cache="true">

This tag helps you control your page breaks:
<br clear="all" style="page-break-before:always" />

PDF:
If you're using apex:pageBlock, etc, the Salesforce theme will not display in the PDF, including the nice rounded page borders, colors, or headers. It'll just appear as different-sized fonts with different weights, etc.

<apex:page standardController="Quote__c" showHeader="false" renderAs="pdf">

CSV:
Note that this page has to be completely clean and display only text that would be accepted in a .csv file. Even using something as basic as "apex:repeat" tend to insert breaks, spaces, and formatting that would be disruptive if you are using the csv file for an upload process that may be fussy. I've found that the best way to do this is to format your entire csv text within your controller class into a string variable, and display just the string in the VisualForce page using {!string} or apex:outputText.

The "#report.xls" tagged at the end of the contentType string will be the name of your file.

<apex:page controller="ReportController" contentType="text/csv#report.csv">
<apex:outputText value="{!csvStr}" />
</apex:page>


Source:
http://www.salesforce.com/us/developer/docs/pages/Content/pages_styling_content_type.htm
http://www.salesforce.com/us/developer/docs/pages/Content/pages_quick_start_renderas_pdf.htm
http://theviewfromouthere.wordpress.com/2009/10/08/turning-a-visualforce-page-into-a-word-document/

Custom Links to Reports

This blog will review how Custom Links can be used in Salesforce.com to provide users quick access to the information necessary to the call and account planning processes.

Custom Links to Reports
Many sales reps will tell you that there are two or three reports that are critical to the planning process.  In most orgs these reports are available under the reporting tab, so reps can access the report and then apply the necessary filters to get specific information relating to a single object (i.e. Account or Contact).  Custom links can be used to run a filtered report directly from a details page – minimizing the number of clicks necessary to get the right information.
To add a custom link that results in a filtered report you will need to pass the object’s unique record ID to the report.
Step 1: Create a new custom report from the reports tab.  On the report apply filters based on how you would like the report filtered in the future and leave the filter value blank (leave the field and operator).  Save the Report.
 
Step 2: Run the new custom report and copy the URL from the browser.  Under Customize in the Setup menu select the object you wish to place the custom link on and select Buttons and Links.
Within the New Button or Link page enter the Label, Name, Description, Display Type, Behavior and Content Source (URL).
Within the code editor paste the URL that you copied earlier.  At the end of the URL append ?pv0= and then use the merge fields drop down to add the appropriate ID.
Step 3: Click save and add the custom link to the appropriate page layouts.
Notes:
  • You may add multiple filters to a custom link by appending ?pv0={id#1}, ?pv1={id#2}, etc.
    pv0 represents the first filter, pv1 represents the second, and so on and so forth.
    i.e. https://na5.salesforce.com/00O700000031j7m?pv0={!Account.Id}?pv1={!Account.OwnerId}
  • Make sure that date ranges are set correctly on a custom report to minimize that chances that there is too much or too little data.
Custom Link to Website
It is very possible that a sales rep may want to search the internet for recent news relating to a field on an object (i.e. Account Name, etc.) or for a map to a location.  This can be quickly accomplished by creating a custom link using standard search queries.
Step 1: Under Customize in the Setup menu select the object you wish to place the custom link on and select Buttons and Links.
Within the New Button or Link page enter the Label, Name, Description, Display Type, Behavior and Content Source (URL).
Within the code editor enter the search URL and use the merge field drop down to select the field(s) you want to search on.
https://www.google.com/search?as_q={!Account.Name}
Step 2: Click save and add the custom link to the appropriate page layouts.
Note:
  • Every search engine uses a different query string.  There are a number of web sites that are dedicated to the parameters.
Custom Link to Document
A sales rep may have a particular document that they frequently reference for an object. Placing a link to a specific document can be done very easily by creating a custom link to a document within Salesforce.
Step 1: Create a folder on the Documents tab with which all applicable users have access, and then upload the document to that folder.
Step 2: Locate the document under the Documents tab, and click View file.
Copy the URL from the browser. Under Customize in the Setup menu select the object you wish to place the custom link on and select Buttons and Links.
Within the New Button or Link page enter the Label, Name, Description, Display Type, Behavior and Content Source (URL).
Within the code editor paste the URL that you copied earlier, omitting the domain prefix (which will be similar to https://na1.salesforce.com)
Step 3: Click save and add the custom link to the appropriate page layouts.
Note:
  • When creating a document in Salesforce, you can either upload a document or provide a URL to reference its location.
  • You may also consider linking to documents on an intranet.  If you decide to do this you will want to make sure users recognize that they need to be connected to the company’s network in case they try to access the document while on a call.

Thursday, February 9, 2012

SFDC Reports

SFDC Reports (Diff b/w Tabualr, Summary, Matrix Reports)

There are 3 kinds of reports in salesforce.com

1) Tabular Reports
2) Summary Reports
3) Matrix Reports

Tabular Reports:- These kind of reports are used when the requirement is just to view the data.
Some of the examples are:-
  • Show me all Open Opportunities
  • Show me List of all Accounts which do not have any closed opportunity
  • Show me top 10 Opportunities by revenue
Dashboards can not be created on Tabular Reports :- Salesforce ADM 201 certification question

Summary Reports:- These reports are used when the requirement is to summarize only X Axis. In short if you need to do the sum or calculate the average on even one parameter then summary report is the answer.
Some of the examples are:-
  • Show sum of all Open Opportunities
  • Show opportunities sub total bu my Team
Matrix Reports:- These reports are used when the requirement is to summarize both the Axis i.e. when requirement is to group both Rows as well as Columns.
Some of the examples are:-
  • Show Accounts grouped as Customer or Prospect depending on the opportunity stage
  • Show monthly performance of salesteam on closing opportunity by Geography for current year
Note:- Charts can not be made on Tabular Reports as no grouping of data is available

SFDC External ID Limitation

Salesforce.com has put some silly restrictions and one of those is limit on No. of Unique fields per object. It allows only 3 External ID fields per object and considers Unique fields as type of external Id's only.

So, you can create maximum 3 Unique fields per object but can get this limit extended by requesting the salesforce via raising a Case.

ADM 201 Question:- Only 3 External ID Fields can be created on an Object.
ADM 201 Question:- Only Text, Email, Number fields can be made External Id fields.

Note:- You can not make a field unique if it contains data which is not unique.

Placing a visualforce page on sidebar

Placing a visualforce page on sidebar is really simple.
1) Create a visualforce page.
2) Create a custom  HTML homepage component. Place the following code in the HTML area.

<iframe src="/apex/[VF PAGE NAME]" width="100%" frameborder="0" height="100"></iframe>

replace [VF PAGE NAME] your custom page name.
3)Place it on the left side of home page layout.

Passing parameters with Command Link

create a command link and pass arguements. In the apex class you can get the parameters and use the value in your code.

Visual Force Page:

<apex:page controller="showCammand">
<apex:form>
<apex:commandLink id="commandLink" action="{!displayName}" value="Show my name">
<apex:param name="Name" value="myName"/>
</apex:commandLink>
<br/>
My name: {!name}
</apex:form>
</apex:page>
 
Apex Class:
public class showCammand()
{
public String name {get; set;}
public void displayName()
{
name = ApexPages.CurrentPage().getParameters().get('Name');
}
}

Using static resource Dynamically

Let’s suppose we have an archive in static resource with name “Contact” and you want to use this static resource on a page that displays Contact Photos dynamically. Assumption is that the images are stored with same name as product codes.
Code:

//Declare an apex variable which gets the Contact code from an apex property
<apex:variable var="contact_photo" value="{!contactPhoto}.jpg"/>
<img src="{!URLFOR($Resource.Products,contact_photo)}')" alt="" />

Wednesday, February 8, 2012

Concept of Tabs in Salesforce.com

Few important things one must know about the TABS are:
  • Tabs can help you in making the views which help user to see the information at a glance. Example: List of all contacts whose birthday is in this month, list of all opportunities which are in negotiation stage.
  • There is a limitation on the number of tabs one can have in their organization, Maximum of 25 tabs are allowed in the enterprise edition.
  • For a profile you can set the status of tabs as "Default On", "Default Off" and "Tab Hidden"
    • Default On: User with this Tab setting will be able to see the Tab for custom object every time he enters in to the SFDC.
    • Default Off: User with this Tab setting will NOT be able to see the Tab for a custom object when he enters in to SFDC but has the ability to add this tab to his view by customizing the tab view.
    • Tab Hidden: User with this Tab setting will be NOT be able to see the Tab for a custom object and even will NOT be able to bring the tab by customizing the tab view settings.
  • Search is enabled only for those custom objects which have a Tab. So if you are unable to search on a custom object then the reason could be that the Tab for that custom object is not enabled in profiles or you have not created the Tab for that object. DEV 401 certification
  • Web Tabs are the tabs from which user goes to the external websites. So use them when you want to divert the user from SFDC to External Systems.

Salesforce.com and its Competitors

Every company wants to have a part of SAAS Pie. Salesforce.com is a clear leader at this point of time but faces stiff competition from some of the prominent well established or very Niche Players.

Some of the key one's are:

Microsoft Dynamics:- A company which charges 25% of what SFDC charges per license and even do not charge for initial 6 months. I am sure they are giving Sleepless nights to Salesforce.com.

Sugar CRM:- This is a CRM which is available Free of cost and that's the only thing which goes against It.

Siebal On Demand / Oracle on Demand, Sage Software, Right Now Technologies

Net Weaver and Business By Design are always seen as the next big thing. Net Weaver has started to prove the point where as people have still big expectations from SAP BByD.

And Be aware about the GOOGLE, They have started looking at the application business very seriously and that's not a good sign for Salesforce.com

Create many to many relationship using Junction object

Junction Object or Many to Many Relationship in SFDC

There is no out of box relationship present in SFDC i.e. Many to Many in nature, So to have a many to many relationship in SFDC a JUNCTION OBJECT is required.

A junction object joins the two objects with two master detail relationship. Junction object is always on the detail side of the object.

A1__c M : 1 Junction (J__c) 1 : M A2__c

This way junction object creates Many to Many relationship between A1__c and A2__c. (DEV 401 Question)

One example of many to many relationship among standard objects is Case and Solution. One case can have many solution attached to it and one solution can be used in resolving many cases.

Q. What is a Junction?
A. Object used for creating many-to-many(m-m) relationship between 2 objects. Junction object will have 2 master-detail fields.
Example: To create m-m relationship between object A1__c and A2__c, create a junction object J__c with Master detail field corresponding to A1__c and A2__c.

Few important points (Interview Questions of salesforce ):
  1. One Object can have only two Master-Detail relationships.
  2. If we delete record A (First Master detail relationship is always primary) – then child record c will be deleted.
  3. If we delete record B then in this case also child record C will be deleted.
  4. If we delete record c then only C will be deleted , master record will not be deleted.