You need to sign in to do that
Don't have an account?
Yao Lin
Unlock record Submit for Approval
Hi,
When a record is submitted for approval, it is locked by default. I created Apex class which unlocks the record submitted for approval on the custom object Sales Order. I already checked Enable record locking and unlocking in Apex in Process Automation setting. However, record is still locked after I submitted it. Can anyone please help?
When a record is submitted for approval, it is locked by default. I created Apex class which unlocks the record submitted for approval on the custom object Sales Order. I already checked Enable record locking and unlocking in Apex in Process Automation setting. However, record is still locked after I submitted it. Can anyone please help?
public class UnlockSOApprovalProcess{ public static void unlockSORecord(PBSI__PBSI_Sales_Order__c soRecord) { Approval.UnlockResult unlockedRersult = Approval.unlock(soRecord); // Iterate through each returned result if (unlockedRersult.isSuccess()) { // Operation was successful, so get the ID of the record that was processed System.debug('Successfully unlocked Sales Order with ID: ' + unlockedRersult.getId()); } else { // Operation failed, so get all errors for(Database.Error err : unlockedRersult.getErrors()) { System.debug('The following error has occurred.'); System.debug(err.getStatusCode() + ': ' + err.getMessage()); System.debug('opportunity fields that affected this error: ' + err.getFields()); } } } }
Hi Yao Lin, can you try adding the without sharing?
public without sharing class UnlockSOApprovalProcess{
Also please verify that the soRecord is the right one.
if it helps please like and mark as correct as it may help others.
I tried public without sharing class. The Sales Order record is still locked.
soRecord is the name I gave to call the object.
Thanks