Nov 10

salesforce To Salesforce Integration Through Apex

    public class salesforceToSalesforceIntegrationThroughApex {

        public void integrateS2S()
        {
            final String LOGIN_DOMAIN = 'login'; //other options: test, prerellogin.pre
            final String USERNAME  = 'user name';
            final String PASSWORD  = 'user password';
        
            String SERVER_URL;
            String SESSION_ID;

            // How to generate Consumer Key and Consumer Secret Code? 

            //Goto Setup > Build > Apps>Connected Apps>New> Enter required data alog with API (Enable OAuth Settings)
            String Consumer_Key = '3MVG9Y6d_Btp4xp7HI0OKNu0NNZ7CbuDa8ISx.u_E6f4e3Q.4MBRzkD3Mi3lzUCwlC3OgO5g5oT.I7xVYt1aB';
            String Consumer_Secret = '766475509074793020';
            
            HttpRequest request = new HttpRequest();
            request.setEndpoint('https://login.salesforce.com'+'/services/oauth2/token');
            request.setMethod('POST');
            request.setHeader('Content-Type', 'application/x-www-form-urlencoded');
            request.setHeader('SOAPAction', '""');
            String reqbody = 'grant_type=password&client_id='+Consumer_Key+'&client_secret='+Consumer_Secret+'&username='+USERNAME+'&password='+PASSWORD;          
            request.setBody(reqbody);
            
            Http hp = new Http();
            HttpResponse response = hp.send(request);
            System.debug('response.getbody()'+response.getStatusCode());
            
            JSONParser parser = JSON.createParser(response.getbody());
            
            OAuth2 objAuthenticationInfo = (OAuth2)JSON.deserialize(response.getbody(), OAuth2.class);         
                if(objAuthenticationInfo.access_token!=null)
                {  
                    SERVER_URL=objAuthenticationInfo.instance_url;
                    SESSION_ID = objAuthenticationInfo.access_token;
                }
            final PageReference theUrl = new PageReference(SERVER_URL + '/services/data/v22.0/query/');
            theUrl.getParameters().put('q','select id,name from Account limit 10');
            request = new HttpRequest();
            request.setEndpoint(theUrl.getUrl());
            request.setMethod('GET');
            request.setHeader('Authorization', 'OAuth ' + SESSION_ID);
            String body = (new Http()).send(request).getBody();
            System.debug('Accounts in JSON format: ' + body);
            JSONParser parser2 = JSON.createParser(body);
                do{
                    parser2.nextToken();
                }while(parser2.hasCurrentToken() && !'records'.equals(parser2.getCurrentName()));
                    parser2.nextToken();
                    final List<Account> accounts = (List<Account>) parser2.readValueAs(List<Account>.class);
                    System.debug('Accounts as native list: ' + accounts);                    
        }

    }

Mar 04

Data Management

Data Management

Data Management is used for to

  1. Export the data from SF Objects to CSV Files by DM Wizards.

  2. Import data from CSV files to SF Objects by DM Wizards.

    1. For What are the objects we can import data from CSV Files.

      1. Custom objects

      2. Solutions, Leads, Accounts/ Contacts

      3. we can store analytical snap shots (by mapping the custom object to the reports storing the reports is called analyticalsnapshot.)

  3. Mass Transfer records, deletion, update address and Approval Request.

  4. Updating State and Country pick list.

  5. We can examine Storage Limits or usage.

  6. Data Loader (Through Command line interpreter we can connect to SF and we can export and import with sale forces) from Desk Top.

Data Export

  1. Export now

  2. we can schedule Export

  3. with in 48hrs the link will be generated though which we can download the csv files.

Data Loder

How to login the Dataloder : Download Data loder form your SF Account >DataManagment > Data Loder 

User Id : your user id

Password : YourPasswordSecurityTocken

  1. Bulk export and import

  2. Insert, Update, Upsert, delete, Hard delete

  3. we can use data loader in tow way 1st User Interface , 2ed. Command line

  4. Support for large files with up to 5 million records where as DM Wizard 50000/- (because it is through browser)

  5. You need to load into an object that is not yet supported by the import wizards

  6. You want to schedule regular data loads, such as nightly imports.

  7. You need to load 50,000 to 5,000,000 records. Data Loader is supported for loads of up to 5 million records. If you need to load more than 5 million records, we recommend you work with a salesforce.com partner or visit the App Exchange for a suitable partner product.

 

Use the import wizards when:

You are loading less than 50,000 records.

The object you need to import is supported by import wizards. To see what import wizards are available and thus what objects they support, from Setup, click Data Management.

You want to prevent duplicates by uploading records according to account name and site, contact email address, or lead email address.

Feb 19

How to use INCLUDES function in Salesforce??

     Salesforce having lot of functions one among them is INCLUDES, it is a Text Function. I observed saleforce Help document also not providing detailed usage of this function. INCLUDES returns Boolean value if the provided single selected value is correct.

Exp: i.e if multipicklist Favorite_Animal__c selected value are (Dog,Cow,Horse)

then a valid INCLUDE function looks like this INCLUDES(Favorite__Animal__c,'Dog');

it will not accept INCLUDES(Favorite__Animal__c,'Dog; Cow; Horse') kind of functions. even it will not accept

INCLUDES(Favorite__Animal__c,'Dog' and 'Cow' and 'Horse') kind of functions.

So INCLUDES is not for check multiple selected values, it is only for to check whether given value is exist or not.

Then what is the use of multypicklist INCLUDE function?

To ensure multiple selected items we should use AND Logical function as follows. AND(INCLUDES(Favorite__Animal__c,'Dog'),INCLUDES(Favorite__Animal__c,'Cow'),INCLUDES(Favorite__Animal__c,'Horse'))

Nov 09

How Search Works in Salesforce?

Search uses custom algorithms that consider:

  • Your search terms
  • Ignored words in search terms (for example, “the,” “to,” and “for”)
  • Search term stems (for example, searching for speaking returns items with speak)
  • Proximity of search terms in a record
  • Record ownership
  • Most recently accessed records

You might not have the same search results as another user performing the same search because searches are configured for the user performing the search. For example, if you recently viewed a record, the record relevancy increases and the record moves higher in your search results list. Records you own also move higher in your search results.

How your search works depends on whether you're using SidebarAdvanced, or Global Search.

Feb 03

Salesforce Apex enum Example

crate a class season,month,MyExample bellow like this
public enum Season {
WINTER,SPRING,SUMMER,FALL
}

public enum Month {
JAN,FEB,MAR,APR,MAY,JUN,JUL,AUG,SEP,OCT,NOV,DEC
}

public class MyExample {
public List seasonMonths(Season s)
{

List listMonths = new List();

if(s==season.WINTER)
{
listMonths.add(Month.DEC);
listMonths.add(Month.JAN);
listMonths.add(Month.FEB);

}
else if(s==season.SPRING)
{
listMonths.add(Month.MAR);
listMonths.add(Month.APR);
listMonths.add(Month.MAY);

}
else if(s==season.SUMMER)
{
listMonths.add(Month.JUN);
listMonths.add(Month.JUL);
listMonths.add(Month.AUG);
}
else if(s==season.FALL)
{
listMonths.add(Month.SEP);
listMonths.add(Month.OCT);
listMonths.add(Month.NOV);
}

return listMonths;
}
/*
Steps to execute this code

System.debug(Season.WINTER);
MyExample obj = new MyExample();
System.debug(obj.seasonMonths(Season.WINTER));
*/
}

Jan 21

SOQL Select all fields (Select * from )

public class ApexSelectQueries {
//SOQL will not support direct select * from syntax, so we need to retrive all field names first then we should construct a select statment with the fields.
//This method generates a SOQL select statement equal to select * from object.
//if your object is Account then your fieldMap should be return type of this statment schema.SObjectType.Account.fields.getMap();
//The return type of this method is string i.e select field1,field2,… from yourObject.
public String selectAll(Map fieldMap,String yourObject)
{
Map fldObjMap = fieldMap;
List fldObjMapValues = fldObjMap.values();
String theQuery=”;
for(Schema.SObjectField sObjField : fldObjMapValues)
{
String theName = sObjField.getDescribe().getName();
theQuery += theName+’,';
}
if(theQuery.lastIndexOf(‘,’)!=-1)
{
theQuery = theQuery.removeEnd(‘,’);
}
theQuery = ‘SELECT ‘+theQuery+’ From ‘+yourObject;
return theQuery.trim();
}
}

Dec 26

Sharing Rules

Sharing rules allow you to selectively grant data access to defined sets of users. Review the following notes before using sharing rules:

  • You can use sharing rules to grant wider access to data. You cannot restrict access below your organization-wide default levels.
  • Sharing rules apply to all new and existing records that meet the definition of the source data set.
  • Sharing rules apply to both active and inactive users.
  • When you change the access levels for a sharing rule, all existing records are automatically updated to reflect the new access levels.
  • When you delete a sharing rule, the sharing access created by that rule is automatically removed.
  • When you transfer records from one user to another, the sharing rules are reevaluated to add or remove access to the transferred records as necessary.
  • When you modify which users are in a group, role, or territory, the sharing rules are reevaluated to add or remove access as necessary.
  • Sharing rules automatically grant additional access to related records. For example, opportunity sharing rules give role or group members access to the account associated with the shared opportunity if they do not already have it. Likewise, contact and case sharing rules provide the role or group members with access to the associated account as well.
  • If multiple sharing rules give a user different levels of access to a record, the user gets the most permissive access level.
  • Users in the role hierarchy are automatically granted the same access that users below them in the hierarchy have from a sharing rule, provided that the object is a standard object or the Grant Access Using Hierarchies option is selected.
  • Regardless of sharing rules, users can, at a minimum, view the accounts in their territories. Also, users can be granted access to view and edit the contacts, opportunities, and cases associated with their territories' accounts.
  • Making changes to sharing rules may require changing a large number of records at once. To process these changes efficiently, your request may be queued and you may receive an email notification when the process has completed.
  • You can create rules to share records between most types of Customer Portal users and Salesforce users. Similarly, you can create sharing rules between Customer Portal users from different accounts as long as they have the Customer Portal Manager user license. However, you can't include high-volume portal users in sharing rules because they don't have roles and can't be in public groups.
  • You can easily convert sharing rules that include Roles, Internal and Portal Subordinates to include Roles and Internal Subordinates instead by using the Convert Portal User Access wizard. Furthermore, you can use this wizard to convert any publicly accessible report, dashboard, and document folders to folders that are accessible by all users except for portal users.
  • Lead sharing rules do not automatically grant access to lead information after leads are converted into account, contact, and opportunity records.
Dec 15

Trigger vs Workflow

 

Trigger vs Workflow
 
S. No. Trigger Workflow
1. Triggers can not be updated on production org after being created via a managed package. Actions in workflows can be edited,removed and new actions can be added
2. More complex logic can be added in the triggers like DML actions on other object than the object on which trigger is written Less Complex logic is supported
3. Trigger get fired on more actions like on insert , update , delete and undelete Workflow get fired on insert and update
4. You can decide excution of trigger whether it should be before or after the initiation action like ( on before insert trigger or on after update trigger) Workflow only gets executed after any insert or update