Lock() and unlock() methods in the System.Approval Class let you lock and unlock records by passing in record IDs or sObjects.
Enable the feature by :-
Setup –> Process Automation Settings –> Enable record locking and unlocking in Apex.
Create a Detail Page Button and associate it with the Visualforce Page and place it on the Page Layout.
Create a Visualforce Page
<apex:page standardController="Order" extensions="OrderLockUnlockController" action="{!unlock}"> </apex:page>
Create a Class
public class OrderLockUnlockController{ private Id recId; public OrderLockUnlockController(ApexPages.StandardController stdCtrl) { recId = stdCtrl.getId(); } public PageReference unlock(){ if (Approval.isLocked(recId)) { Approval.unlock(recId); } PageReference pageRef = new PageReference('/'+recId); pageRef.setRedirect(true); return pageRef; } }