Reply
Regular Contributor
Tena
Posts: 34
0

RunAs to update locked Opportunity

I have an object that is linked to an Opportunity.  When this object is updated it needs to update the opportunity.  However, in some cases the opportunity is in an approval process and this causes the error "; first error: ENTITY_IS_LOCKED, the entity is locked for editing: []".  Can I use the RunAs to make the class run under an administrator because even though this opp is locked it needs to be updated.  I only see runas used in Test Classes.

 

Thanks,

 

Tena

Regular Contributor
Rakeshistom011
Posts: 37
0

Re: RunAs to update locked Opportunity

<p>Like other Apex classes, all custom controllers run in system mode. Consequently, the current user's credentials are not used to execute controller logic, and the user's permissions and field-level security do not apply. So you can't use RunAs().</p>

Thanks,
Rakesh Kumar LinkedIn
Salesforce Certified developer, Administrator, Consultant
Answers/Suggestions are my own.
If a reply to a post answers your question or resolves your problem, please mark it as the solution to the post so that others may benefit.

Regular Contributor
Tena
Posts: 34
0

Re: RunAs to update locked Opportunity

According to what I read about system mode is that it doesn't take the user into consideration when running the code.  I find this odd becasue when an opportunity is locked and a user exectues a trigger that I wrote there is an error of  "ENTITY_IS_LOCKED".   However, if I do the exact same thing as an administrator I don't get the error. Does this mean then that the opportunity being locked has nothing to do with this issue?

 

Thanks,

 

Tena