0

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.

2

This is the default behavior. System Admins (i.e. users with permission of Modify All/Modify All Data) can edit the locked records. Here is the link which states the same. You can go through this article which mentions what permissions are needed to edit the locked records.

If you are not seeing the lock/unlock button in the page layout, you need to check following points.

  • Lock/Unlock button will be visible only for users with Modify All/Modify All Data permission
  • Disable "Enable Separate Loading of Related Lists" setting under user interface

And if the user has Modify All/Modify All Data permission or is assigned as currently assigned approver, then that user will be able to edit the record without having to click on Unlock button. Lock/Unlock button is just to lock/unlock the record. System Admins (Modify All/Modify All Data) can directly click on edit button and edit the record.

  • Yes, i agree that user with "Modify All/Modify All Data permissions" can able to Edit the records. But that will happen only after unlocking the record (After clicking on Unlock Button). Here the concern is, user is not able to see the Unlock button and record is editable by the users who don't even have the "Modify All/Modify All Data permissions". – Aishwary Jan 30 at 7:49
  • Updated the answer, can you check the mentioned points and see if it works. – Vijay Ganji Jan 30 at 12:26

Your Answer

By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

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