Salesforce Stack Exchange is a question and answer site for Salesforce administrators, implementation experts, developers and anybody in-between. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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?

share|improve this question
up vote 19 down vote accepted

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.

share|improve this answer
Interesting. Is your code straight in a trigger or in a class marked without sharing? I'd swear it fails when I tried some time ago with sharing. I actually want it to fail on the lock, saved me time spelling out a val. rule / trigger that users shouldn't change detail lines when master is in approval. They were changing lines, rollup recalc kicks in, boom, blocked. I need to retest it then :/ – eyescream Dec 13 '12 at 7:29
It was straight in a trigger. Didn't try it using with sharing. Maybe a little more testing is in order. – Daniel Hoechst Dec 13 '12 at 14:19
@eyescream I updated the answer as it does depend on how the class is marked for sharing. – Daniel Hoechst Dec 13 '12 at 15:35
Awesome. Thx for checking! – eyescream Dec 13 '12 at 15:46

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".

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.