+ Start a Discussion
Jenny Mosunova TelitJenny Mosunova Telit 

unlock record

I used this code to unlock records after they enter approval process:

// Query the accounts to unlock
Account[] accts = [SELECT Id from Account WHERE Name LIKE 'Acme%'];
// Unlock the accounts
Approval.UnlockResult[] urList = Approval.unlock(accts, false);

// Iterate through each returned result
for(Approval.UnlockResult ur : urList) {
    if (ur.isSuccess()) {
        // Operation was successful, so get the ID of the record that was processed
        System.debug('Successfully unlocked account with ID: ' + ur.getId());
    else {
        // Operation failed, so get all errors                
        for(Database.Error err : ur.getErrors()) {
            System.debug('The following error has occurred.');                    
            System.debug(err.getStatusCode() + ': ' + err.getMessage());
            System.debug('Account fields that affected this error: ' + err.getFields());

Using debug logs I can tell that it is unlocking the record when it is submitted for approval.  But in the UI it still has the unlock button and the record is locked.  So is the "Approval.unlock()" method used specifically to unlock the record only for apex users?  Does record lock itself again after all code run?  Is there something I can do to keep the record unlocked so a user can still edit it?
The thing is, it works on Admin Profile user but not on other Profiles, despite I get success in Approval.UnlockResult for both. I assume that the problem might be in permissions, anyone knows something regarding this issue?  Thanks
where is this code in a visualforce page?
Jenny Mosunova TelitJenny Mosunova Telit
This is in trigger, not in visualforce page...
also is the UI a standard UI if so the issue is elswhere if not try rerendering the Page
Jenny Mosunova TelitJenny Mosunova Telit
It is on regular Account Page Layout, but the issue is not in the UI, the problem is the function does not really unlock the record.