+ Start a Discussion

Unlock record from apex

I am trying to unlock the records locked from approval process using apex. I am trying to do it in the After Update context. Can I update same record in after update context?
Here is my sample code
public static void unlockApprovalLockedRecords(list<customObject> records){
        for(customObject sp : records){

I am using handler classes and calling this method from the handler class.
Thank you.
Om PrakashOm Prakash
Yes you can unlock the record from after update context.
If you are getting System.NoAccessException then you need to follow bellow steps in your org:
Go to
Setup > Create > Workflows and Approvals > Process Automation Settings
And mark the checkbox  Enable record locking and unlocking in Apex as true and save.
User-added image
Pradeep SinghPradeep Singh
To update in after Update, you have to query the record/s from the database and then perform action on that record/s and do Update DML on these.