salesforce data migration services

Learn Salesforce Formulas with Examples-Part 3

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 third 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 11

User needs to be create  formula field which returns a checkbox,the checbox must be true if all the below conditions are satisfied :
If the owner is equal to one of 4 users(say 15 Digit User Ids are known)
If loggged in date must be greater than the specific date say example Nov 11, 2015.

AND(
CASE(
OwnerId,
“15_DIGIT_USER_ID_1”, 1,
“15_DIGIT_USER_ID_2”, 1,
“15_DIGIT_USER_ID_3”, 1,
“15_DIGIT_USER_ID_4”, 1,
0
)
= 1,
TODAY() > DATE(2015,11,11)
)

Explanation

Here AND is used to combine two conditions(We used AND since the user wants all checkbox to be true only when all the conditions areTRUE,IOR would have been used when User would have required  either of the condition to TRUE)

CASE() function is used which should return 1 and TODAY() should be greater than DATE (where DATE(YYYY,MM,DD)  function is used to get the DATE)

Example 12

User needs to create a formula field for a validation rule on Account Object such that its custom field  (date type) must not be greater than a specified date let’s say 01/11/15

Custom_Date__c > DateValue(“2015-01-11”)

Explanation

Please note that if you compare the Custom_Date__c as : Custom_Date__c > 01/11/15 ,then you would get an error something like: Incorrect parameter type for operator ‘>’. Expected Date, received Number. DateValue Method will convert the String to a Date Format.Please check here for more DateTime methods.

Example 13

User needs a forumla for a validation rule that allows users to enter a date in a custom date field, that can only go 10 days in the past hwen compared with today

(TODAY() – Custom_Date__c) > 10

Explanation

Two dates can be directly subtracted and there result will be always an integer.Please check here for more DateTime methods.

Example 14

User need to write a formula field for a validation rule such that for  a given record type (15 Digit record type Id provided),User must fill something in Description Field when case status is put to closed.

AND (
RecordTypeId <> “15_Digit_Id”,
ISPICKVAL( Status,”Closed”),
len (Description)=0
)

Explanation

Here three things are considered,Checked if the record typeId is as desired,Status is closed,and Length of description field is 0.

Example 15

User want to prevent other users to edit two fields on Cases (Means lock those fields) when the case status is pending

AND(
       OR(
             ISCHANGED(Field1__c),
            ISCHANGED(Field2__c)
            ),
      ISPICKVAL(Status, “Pending”)
)

Explanation:

Here OR will check if either of two fields are changed.AND will combine OR condition and check if status is pending