switch

Compares an input value against a list and returns a corresponding value or error message in Salesforce Spiff. This function is similar to the vlookup() function except the lookup tables are specified within the function rather than in a lookup table.

Required Editions

Available in: both Salesforce Classic (not available in all orgs) and Lightning Experience
Available in: Enterprise, Unlimited, and Developer Editions
Available for an additional cost in: Professional Edition with Web Services API Enabled

Syntax

switch(value_to_switch, list_of_value_and_result_pairs)

Arguments

Argument Required? Description
lookup_value Required The record or value that you want to compare.
list_of_value_and_result_pairs Required A list of value pairs, where each pair includes a value to match against lookup_value and a return value for that match. Enclose the list in brackets with comma-separated values. To specify an error message, such as when the list doesn't include lookup_value, the last item in the list can be a string that you want to show to admins.

Example

The Corporate AE Plan has a 10% commission rate and the Enterprise AE Plan has a 12% commission rate. Look up the plan name and apply the appropriate commission rate. Show an error message if the plan name isn't included in the list.

=switch(plan.name, ["Corporate AE PLan", "10%", "Enterprise AE Plan", "12%", "We couldn't find a rate for that plan name."])