You need to sign in to do that
Don't have an account?
PEDRO PRADA
Unlock approval using apex certain condition
Hi everyone, this is my first post seeking some assistance. I am new to Apex and looking to get some code to get it to work....
The business requirement is that an approval is unlocked after 30 days of approval date and that the standard field status is set to "Expired" (have not added this to logic.
Can someone look at this code and tell me how to fix it and add the logic to set the quote.status to expired?
public class UnlockApprovedDelivery //Get records to unlock
{
List<Quote> quoteList = [SELECT Id From Quote WHERE Rate_Expiry_Date__c > TODAY];
//Check locked records
List<Quote> quoteLockList = new List<Quote>();
for(Quote q:quoteList){
if(Approval.isLocked(q.id)){
quoteLockList.add(q);
}
}
//Unlock record
if(!quoteLockList.isEmpty()){
//Unlock records
List<Approval.UnlockResult> ulrList = Approval.unlock(quoteLockList, false);
// Iterate through each returned result
for(Approval.UnlockResult ulr : ulrList) {
if (ulr.isSuccess()) {
//Operation was successful, so get the ID of the record that was processed
System.debug('Successfully locked account with ID: ' + ulr.getId());
}
else {
//Operation failed, so get all errors
for(Database.Error err : ulr.getErrors()) {
System.debug('The following error has occurred.');
System.debug(err.getStatusCode() + ': ' + err.getMessage());
System.debug('Case fields that affected this error: ' + err.getFields());
}
}
}
}
The business requirement is that an approval is unlocked after 30 days of approval date and that the standard field status is set to "Expired" (have not added this to logic.
Can someone look at this code and tell me how to fix it and add the logic to set the quote.status to expired?
public class UnlockApprovedDelivery //Get records to unlock
{
List<Quote> quoteList = [SELECT Id From Quote WHERE Rate_Expiry_Date__c > TODAY];
//Check locked records
List<Quote> quoteLockList = new List<Quote>();
for(Quote q:quoteList){
if(Approval.isLocked(q.id)){
quoteLockList.add(q);
}
}
//Unlock record
if(!quoteLockList.isEmpty()){
//Unlock records
List<Approval.UnlockResult> ulrList = Approval.unlock(quoteLockList, false);
// Iterate through each returned result
for(Approval.UnlockResult ulr : ulrList) {
if (ulr.isSuccess()) {
//Operation was successful, so get the ID of the record that was processed
System.debug('Successfully locked account with ID: ' + ulr.getId());
}
else {
//Operation failed, so get all errors
for(Database.Error err : ulr.getErrors()) {
System.debug('The following error has occurred.');
System.debug(err.getStatusCode() + ': ' + err.getMessage());
System.debug('Case fields that affected this error: ' + err.getFields());
}
}
}
}
i have added some logic in this code in unlock record. its not qccurate one so u need to align this code. and create on custom date field in quote to update record approve date. so that we can calculate days.
hope this will give you some idea.
Thanks
karthik