On Using "Approval.LockResult" class, In debug logs i can see the records are successfully locked but in reality the records are not saved and i cannot even see the lock/unlock button on record detail page.
Below is the code:
// Query the accounts to lock
Account[] accts = [SELECT Id from Account WHERE Name LIKE 'Ab%'];
// Lock the accounts
Approval.LockResult[] lrList = Approval.lock(accts, false);
// Iterate through each returned result
for(Approval.LockResult lr : lrList) {
if (lr.isSuccess()) {
// Operation was successful, so get the ID of the record that was processed
System.debug('Successfully locked account with ID: ' + lr.getId());
}
else {
// Operation failed, so get all errors
for(Database.Error err : lr.getErrors()) {
System.debug('The following error has occurred.');
System.debug(err.getStatusCode() + ': ' + err.getMessage());
System.debug('Account fields that affected this error: ' + err.getFields());
}
}
}
NOTE: 1. User have ModifyAll access to Object and also have ModifyAllData system permission. 2. As part of prerequisite, i have also enabled the 'record locking and unlocking in Apex' process automation setting.