salesforce data migration services

Learn Salesforce Formulas with Examples-Part 1

Inspired by a lot of problems related to formulas posted in Answers Community ,I decided to put blog series “Learn Salesforce Formulas with Examples  and here I am with first post in the Series.

Main motive for this blog is not to teach you how to begin with formula but how to keep a grip and make a better understanding on it..So stay tuned and I will be providing a lot of examples with explanations in this series which would help you understand more about formulas .

Example 1

User needs to be able to determine accounts that have been created from the Lead conversion process and “ideally” be able to see which Campaign they were generated from, so something like Lead Source on Account.

Here is a Simple solution to ensure your custom Lead Source field on Accounts matches your Lead record Lead Source after conversion:

  1. Create a Custom Account Lead Source Picklist on Account Object.
  2. Create a custom formula field on Leads (Text) with Formula = TEXT(LeadSource) .
  3. TEXT function will retrieve values from picklist.
  4. Map this field to your custom Account Lead Source picklist.

Example 2

User would like to add Last 7 Days formula to a field in an XYZ object

We need to use below formula:

IF((TODAY() – DATEVALUE(CreatedDate)) <= 7,1,0)

Explanation : Here TODAY() returns the current date as a date data type. DATEVALUE returns a date value for a date/time or text expression.

You can learn more on how to use Date and DateTime functions here.

Example 3

Users want to put a formula for  Validation Rule that restricts the ability to change ownership to only System Administrators on records for a specific record type.

Below Formula is used:

AND(
ISCHANGED(OwnerId),
$Profile.Name <> “System Administrator”,
RecordType.Name = “Your Record Type Name”
)

Explanation : Here We have checked Profile Name,Name of the Record Type and below two functions:-

  1.   ISCHANGED-Compares the value of a field to the previous value and returns TRUE if the values are different. If the values are the same, this function returns FALSE.
  2. AND– Evaluates if all values or expressions true.

Example 4

Users want a formula for a workflow rule Criteria which has to be triggered when

  • Case record type is set to Type1 or Type2 or Type3.
  • Case Status is Open.
  • It’s should work on newly created Case records and if record types of  existing record are modified.

Below Formula is used:

AND(
         ISPICKVAL(Status, “Open”),
        OR(
                ISNEW(),
               ISCHANGED(RecordTypeId)
             ),
        OR(
             RecordType.Name = “Type 1”,
            RecordType.Name = “Type 2”,
          RecordType.Name = “Type 3”
         )
)

Explanation:  Below Functions are used:

  1. ISPICKVAL-Determines if the value of a picklist field is equal to a text literal you specify
  2. ISCHANGED-Compares the value of a field to the previous value and returns TRUE if the values are different. If the values are the same, this function returns FALSE.
  3. ISNEW()-Checks if the formula is running during the creation of a new record and returns TRUE if it is. If an existing record is being updated, this function returns FALSE.

 

Example 5

User wants to set a formula critiera for a workflow rule which tiggers unless a field is empty or starts with “A” or “B” or “C”.
Lets Say the field is “Field__c”

Below Formula is used:

AND

(

     NOT(ISBLANK(Field__c)),

     NOT(BEGINS(Field__c, “A”)),

     NOT(BEGINS(Field__c, “B”)),

    NOT(BEGINS(Field__c, “B”))        

)

Explanation: In the above formula we have combined all the four conditions with AND,so this workflow rule will trigger only when these four conditions are met.Two Functions used here are:

  1. ISBLANK-Determines if an expression has a value and returns TRUE if it does not. If it contains a value, this function returns FALSE.
  2. BEGINS-Determines if text begins with specific characters and returns TRUE if it does. Returns FALSE if it does not.