Sometimes we have faced business requirement to Lock or Unlock records in Salesforce. We can use apex lock() and unlock() methods in the System. Approval namespace to lock and unlock records by passing in record IDs or sObjects.
The new Approval.UnlockResult class contains methods that show
the results of record unlocks by System.Approval.unlock() methods.
A Boolean value that is set to true if the unlock operation is successful
for this object, or false otherwise.
Boolean result = System.Approval.unlock(oppId).isSuccess();