Loading
Prepare for Email to Become the Default Login ExperienceRead More
Ongoing maintenance for Salesforce HelpRead More
Extend Salesforce with Clicks, Not Code
IF

IF

Determines if expressions are true or false. Returns a given value if true and another value if false.

Use

IF(logical_test, value_if_true, value_if_false) and replace logical_test with the expression you want evaluated; replace value_if_true with the value you want returned if the expression is true; replace value_if_false with the value you want returned if the expression is false.

Tips

  • Make sure your value_if_true and value_if_false expressions are the same data type.
  • When using an IF function with the $Profile.UserType variable to determine the type of Salesforce user license the logged in user has, use the following values:
    • Standard for Salesforce
    • PowerPartner for PRM User
    • CustomerSuccess for Customer Portal User
    • PowerCustomerSuccess for Customer Portal Manager

    For example, use the following formulas to determine if the logged in user has the license type in quotes:

    IF(ISPICKVAL($Profile.UserType ,"Standard"), 100, 0.1)
    IF(ISPICKVAL($Profile.UserType ,"PowerPartner"), 100, 0.1)
    IF(ISPICKVAL($Profile.UserType ,"CustomerSuccess"), 100, 0.1)
    Note
    Note $Profile merge fields are only available in Enterprise, Unlimited, Performance, and Developer Editions.
Formula Field Example: Overdue Payments
Formula Field Example: Overdue Payments

IF(AND(Payment_Due_Date__c < TODAY(),​​Payment_Status__c ="UNPAID") , "PAYMENT OVERDUE", ​null)

This formula determines if the payment due date is past and the payment status is “UNPAID.” If so, returns the text “PAYMENT OVERDUE” and if not, leaves the field blank. This example uses a custom date field called Payment Due Date and a text custom field called Payment Status.

Formula Field Example: Insert Tax Rate
Formula Field Example: Insert Tax Rate

Use this default value formula to set the tax rate of an asset based on the user's city. Create a custom percent field with the following default value:

IF($User.City = "Napa", 0.0750, 
 IF($User.City = "Paso Robles", 0.0725, 
  IF($User.City = "Sutter Creek", 0.0725, 
   IF($User.City = "Los Olivos", 0.0750, 
    IF($User.City = "Livermore", 0.0875, null
    )
   )
  )
 )
)
Custom Button Example
Custom Button Example
{! 
IF(Sample.BillingCountry = "US", 
"http://maps.google.com/maps?q=​"&Sample.BillingStreet&​
"+"&Sample.BillingCity&"+​"&Sample.BillingState&"+​"&Sample.BillingCountry, 
(IF(Sample.BillingCountry = "UK", 
"http://maps.google.co.uk/maps?q=​"&Sample.BillingStreet
&​"+"&Sample.BillingCity&​"+​"&Sample.BillingCountry, 
"http://maps.google.com"))) 
}

This example uses the IF function to determine if an address is in the United States or United Kingdom so that it can use the appropriate type of Google map to display the address.

 
Loading
Salesforce Help | Article