[SalesForce] Character Limit exceeded in Validation Rule

I Have Validation rules with below rule
OR(Profile.name='Pname1',Profile.name='Pname',Profile.name='Pname3', and so on….)
I have almost 100 profile names which i am not able to listed down in one validation rule.

workaround please. I have created 2 validation rules instead of one.
But is there any solution ,so i can use only one validation rule.
Please Suggest

Best Answer

I can think of a few different approaches that you could take here. These suggestions may be able to be combined.

Option 1

Consider using $UserRole instead of $Profile. This would benefit you if multiple profiles are covered by a single role

Option 2

Use the CASE() function to remove as much repetition as possible. This would look like

IF(
    CASE(Profile.Name,
        'PName1', 1,
        'PName2', 1,
        ...
        'PName90', 1,
        -1
    ) > 0,
    true,
    false
)

In this example, if the profile name was one of the 90 specified, the validation rule would trip, preventing the operation from occurring. It's easy enough to flip around so that the 90 specified profiles would be allowed to complete the operation.

Option 3

Handle this with a Hierarchy Custom Setting. It'd have at least one checkbox. Set the default value for the org to true or false, then add your 90 profiles, setting the value to the opposite of the default org value.

Assuming your Custom Setting is named MyCustomSetting, and your field is named AllowOperation you validation rule would become simply

$Setup.MyCustomSetting__c.AllowOperation__c

The downside of using a Custom Setting is that you would need to re-enter the data in any sandboxes you have (after creating or refreshing the sandbox, except for full copy sandboxes, and maybe partial copy sandboxes as well). You could use the DataLoader to manage this, but it is an extra step.

If you need to use this same profile-checking logic in multiple validation rules (and/or in apex or Visualforce pages), it may be worth it to go with the Custom Setting route.

If this is a one-off validation rule, I'd suggest trying to combine options 1 and 2.

Related Topic