0

I have the following formula in my Validation Rule on Opportunity. The rule should only apply to Lightning and Classic users, but not to incoming APIs. I thought this would allow APIs by without erring, but apparently both Dev Console and Classic view are considered Theme3. What? Why would Theme3 apply to anything other than Classic view?

I realize I may have to filter on Profile instead, but we have reasons why that's really not preferred.

I've been at this for a few hours. Could really use your insight.

AND( 
     OR(
        $User.UIThemeDisplayed=='Theme1',
        $User.UIThemeDisplayed=='Theme2',
        $User.UIThemeDisplayed=='Theme3',
        $User.UIThemeDisplayed=='Theme4d',
        $User.UIThemeDisplayed=='Theme4t',
        $User.UIThemeDisplayed=='Theme4u'
     ),
     RecordType.Name == 'Renewal Quote',
     OR(
        ISPICKVAL(Reason_For_Closed_Lost__c, 'Closed Other – Trade Up/Tech Refresh'),
        ISPICKVAL(Reason_For_Closed_Lost__c, 'Closed Other - Duplicate')
     ),
     ISBLANK(Dup_Opp_TRO_New_Opp__c)
)
2
  • When I remove "$User.UIThemeDisplayed=='Theme3'" from the formula above, then my Oppty Update from Anonymous in Dev Console allows the update, which is good. But my Oppty Update from Classic view also allows the update, which isn't good. Sep 2, 2020 at 7:15
  • I also tested with a Batch Job and Scheduled Batch. Same results. Sep 2, 2020 at 7:17

1 Answer 1

1

There are different ways you can achieve your requirement:-

  1. Using custom permission:- Create a custom permission and assign that permission to the profile which uses API to create/Update opportunity.

    $Permission.isAPIUser

  2. Using profile - Check for Profile Id of the user

    $Profile.Id

  3. Using custom field on User record - Create a custom checkbox field on user and use that field in the validation rule which will allow that particular user to bypass the validation rules

    $User.ByPassValidation__c

With these options you won't need to depend on user's theme to determine whether to skip validation rule or not.

2
  • 1
    #1 works great! Thanks! Created the Custom Permission called "BypassValidationRules". Then created a Permission Set called "Bypass Validation Rules", and added my Custom Permission to it. Now I can assign the Permission Set to any User. And on any Validation Rule (on any Object), I can simply add NOT($Permission.BypassValidationRules) to the formula! Now all users with that Permission Set bypass Validation Rules with the NOT condition. Simple and sweet! Thanks MC :) Sep 2, 2020 at 19:40
  • Glad to be of help :-) Sep 3, 2020 at 1:31

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .