Tag Archives: Formula Field

Formula Field to Convert 15 Character ID to 18 Character ID

Follow the below steps to create a formula field that will give you the 18 characters ID of the records.

  • Go to Setup | Customize | object name | click Fields
    (For Custom objects: Setup | Create | Objects | Object Name)
  • In the related list “Custom Fields & Relationships” click New.
  • Click the Formula radio button.
  • Click the Text radio button for “Formula Return Type”.
  • 6. Input the following Formula into the Formula Editor:
  • Set Field Visibility, add/ remove from Page Layout(s).
  • Click Save.

NOTE: When dealing with record types only custom record types have ids.

How to create a report that shows user license?

To display Salesforce as a User License type on report, Below is the workaround:

  • Create a Custom Formula Text field under the User object:
    1. Go to Setup | Customize | Users | Fields
    2. Click on New and select “Formula” field type and then “Text”
    3. Use “Profile.UserLicense.Name” in the formula editor
    4. Click on Save
  • Create a New Administrative User report:
    1. Go to the Report tab
    2. Click on New report
    3. Under the Administrative reports | Select Users
    4. Add the New Custom Formula field in the report
    5. Run the Report and Save

Difference Between Two Datetime Fields in Salesforce Formula Field

Sample Code:

IF (FLOOR((EndDateTime__c - StartDateTime__c)) > 0, TEXT(FLOOR((EndDateTime__c - StartDateTime__c)) ) & " Days ", "") 
& IF(FLOOR(MOD((EndDateTime__c - StartDateTime__c)* 24, 24 )) > 0, TEXT(FLOOR(MOD((EndDateTime__c - StartDateTime__c)* 24, 24 ))) & " Hours ","") 
& TEXT(ROUND(MOD((EndDateTime__c - StartDateTime__c)* 24 * 60, 60 ), 0)) & " Minutes "
& TEXT(ROUND(MOD((EndDateTime__c - StartDateTime__c)* 24 * 60*60, 60 ), 0)) & " Seconds" 

Salesforce Sample Image Link Formulas

Flags: This formula displays a green, yellow, or red flag image to indicate case priority.

CASE( Priority, 
"Low", "/img/samples/flag_green.gif",
"Medium", "/img/samples/flag_yellow.gif",
"High", "/img/samples/flag_red.gif", 
"Priority Flag")

Colors: This formula displays a 10 x 10 pixel image of a red, yellow, or green, depending on the value of a Case Age custom number field.

IF( Case_Age__c > 20, 
IMAGE("/img/samples/color_red.gif", "red", 10, 10),
IF( Case_Age__c > 10,
IMAGE("/img/samples/color_yellow.gif", "yellow", 10, 10),
IMAGE("/img/samples/color_green.gif", "green", 10, 10)

Lights: This formula displays a green, yellow, or red traffic light images to indicate status, using a custom picklist field called Status.

"Green", "/img/samples/light_green.gif",
"Yellow", "/img/samples/light_yellow.gif",
"Red", "/img/samples/light_red.gif", 
"status color")

Stars: This formula displays a set of one to five stars to indicate a rating or score.

"1", "/img/samples/stars_100.gif",
"2", "/img/samples/stars_200.gif",
"3", "/img/samples/stars_300.gif", 
"4", "/img/samples/stars_400.gif", 
"5", "/img/samples/stars_500.gif", 

Circles: This formula displays a colored circle to indicate a rating on a scale of one to five, where solid red is one, half red is two, black outline is three, half black is four, and solid black is five.

"1", "/img/samples/rating1.gif",
"2", "/img/samples/rating2.gif",
"3", "/img/samples/rating3.gif", 
"4", "/img/samples/rating4.gif", 
"5", "/img/samples/rating5.gif", 

Priority: This formula displays a red colored priority sign to indicate a priority picklist value.

"Very Low", "/img/samples/rating1.gif",
"Low", "/img/samples/rating2.gif",
"Medium", "/img/samples/rating3.gif", 
"High", "/img/samples/rating4.gif", 
"Very High", "/img/samples/rating5.gif",