A lookup field in a custom object needs to be updated after the record is submitted for approval and locked.
Is the trigger able to achieve this, even if the record is locked?
Attribution to: jmrjulian
Possible Suggestion/Solution #1
It is if the user is ;)
If the action is initiated by System Administrator - sure. Otherwise - tough luck, exception will be thrown. It also depends if you've configured the approval process to "Administrator or current approver can edit the records".
Attribution to: eyescream
Possible Suggestion/Solution #2
The answer is, it depends.
If you have your code written directly in the trigger or in a class designated without sharing
, then the apex code can update records that are locked, regardless of the user who caused the trigger to fire. I tested by creating a trigger on Contact that updates a field on the Contact's Account. When the Account is locked, I can edit the contact record with a non admin user and the field on the Account gets updated.
If you use code in a class marked with sharing
that is called by the trigger, then you will get an exception. If the trigger was executed by an Administrator, then the code will always run.
Attribution to: Daniel Hoechst
This content is remixed from stackoverflow or stackexchange. Please visit https://salesforce.stackexchange.com/questions/5377