|

“Transient” Salesforce validation rules

There are some Salesforce records that can be classified as being “transient” – meaning they change from one stage to another over time. For example, Leads, Opportunities, and Cases are common examples. As the record progresses from initial creation to completion, additional information is added.

This is where applying validation rules to enforce data entry becomes a little bit tricky.

If we take an Opportunity record as an example, when it is first created, little information is known about the customer, the deal, and the products the customer is interested in. Over time, as the record moves from one stage to another, additional information becomes known, allowing the Opportunity to continue to move forward.

At stage 1 – Prospecting, we may not know the initial source of the lead, so requiring that field to be mandatory on initial record creation may in fact, be counterproductive and force the Sales Reps to guess which value the Lead Source field should have. If we later rely on that field to help direct our Marketing efforts, we may be relying on incorrect information.

Our validation rule then becomes more complex, taking into account the stage name and whether it was changed from Prospecting:

AND (
ISPICKVAL(LeadSource,”),
NOT(ISPICKVAL(StageName, ‘Prospecting’)),
ISCHANGED(StageName)
)

There are now three conditions that must all be true for an error to occur:

  1. The Lead Source field must be empty AND
  2. The Stage Name must not be Prospecting AND
  3. The Stage Name must have been changed when editing this record.

This now allows the Opportunity to be created without a Lead Source, but it cannot progress forward until this field is completed.

Note: The fields LeadSource and StageName are both picklists, so the ISPICKVAL function must be used to determine their value.

Similar Posts