Checks whether an expression results in an error or null value in Salesforce Spiff and either returns the result of the expression or returns a default value for error handling. This function provides an alternative nested if() statements, but this function can also disguise real errors and result in inaccurate calculations if not used carefully.
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
iferror(expression, error_expression)
Arguments
| Argument | Required? | Description |
|---|---|---|
| expression | Required | The condition to test. |
| error_expression | Required | The error handling to execute when the expression results in an error or null value. |
Considerations
This function doesn't discriminate which errors to handle. For example, maybe you're trying to prevent a divide-by-zero error for this formula.
if(DenominatorField = 0, 0, DivisionCalculation)
When you use iferror(DivisionCalculation, 0), an error can occur in the numerator, denominator, or any part of the calculation. Each error returns 0 with no error message.
The iferror() function also breaks the trace. If the if(DenominatorField = 0, 0, DivisionCalculation) expression includes ARR divided by quota, attainment appears as 0 on the statement and ARR and quota appears as 0 or not a number for the record. When you specify a divide-by-zero check, you see the values for ARR and quota if they exist.
Example
A rep has a custom rate assigned by a quota table, and you want to check whether the rate for a rep is empty. If so, prompt the admin to specify a rate for the rep. For the expression to test, calculate the rep's rate. For the error_expression argument, use the error() function to show a message for resolving the error condition.
=iferror(DealMRR * AESpecialRates, error(concat(["Enter rates for", rep.name, "on the AESpecialRates quota page."])))
iferror() function is helpful when you're creating calculations and want to test for missing logic or variables. To prevent errors in production logic, use the iferror() function only during development and testing.