Hi Pranav,
You can unlock the records through apex code by enabling Apex code to set and remove approval process lock.This features is avaliable in summer 16 release only. To do this follow these step :-
- Goto Setup
- .Then search ‘Process Automation Settings’ in search box.
- There you click the checkbox ‘Enable record locking and unlocking in Apex’
From this you can enable the record locking and unlocking by apex code.
Then the code for unlocking the record :-
For(sObject a :[select name From sObject])//Name of the object on which lock is acquire
{
if(Approval.isLocked(a.id)){ //To check whether the record is locked or not
Approval.unlock(a.id); //Id of the record which you want to unlock
}
}