function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
Vinnie Bacon 20Vinnie Bacon 20 

How do I get a trigger to run as a sys admin?

We don't do typical Lead conversion.  Thus, I have a validation rule that applies to non-sys admins that prevents them from setting a Lead to a status of 'Converted'.  That rule works fine and gives the user an error message telling them how they should convert a Lead.

Instead, if the user enters a specific field on the Lead, it is considered converted and I want to set the status to that.  I have a trigger that sets the status and does some other things.  However, even with the trigger it's the non-admin user doing the saving of the Lead and the validation rule kicks in.

Any ideas how to get around this?  I tried a future method in the trigger but it seems to silently obey the validation rule.
ANUTEJANUTEJ (Salesforce Developers) 
Hi Vinnie,

I searched for the same and I found the below link can you please have a look at them once below are the links that I found.

>> https://salesforce.stackexchange.com/questions/106405/how-to-execute-and-run-a-trigger-as-a-system-administrator

>> https://salesforce.stackexchange.com/questions/10350/make-validation-rule-bypass-if-trigger-is-run/10353#10353

In case if this comes handy can you please choose this as the best answer so that it can be used by others in the future.

Regards,
Anutej
Vinnie Bacon 20Vinnie Bacon 20
I realized that doing this via a validation rule was not the way to go about it.  Whatever the trigger code does behind the scenes, the final saving of the record is done by the user and subject to the validation rule.  The better way was to deal with it right in the trigger.  First, the trigger checks that a non-admin isn't saving fields like they shouldn't be doing.  If so, it gives an error on the record which stops the update. Otherwise, it proceeds to do the other things in the trigger.