+ Start a Discussion
Soundar Raj PonpandiSoundar Raj Ponpandi 

Approval Process - Auto approve and assign to next approver

Hi,

1. I created one approval process with three level of approvers.

2. Approver 1, Approver 2 and Approver 3.

3. If approver 1 submitted for approval, It should get auto approval and assign to approver 2.

4. If approver 2 submitted it should skip approver 1 and auto approved in approver 2 level,Then assign to approver 3 for approval.

Is that possible by configuration ? else can you please share sample customizaton code.

Regards,
Soundar.
AnudeepAnudeep (Salesforce Developers) 
Hi Soundar, 

I recommend going with Apex Approval Processing because If approver 1 is submitted for approval, It should get auto-approval and assign to approver 2. - There is an option "Approve or reject based on the FIRST response" but it does not auto-approve

User-added image

I recommend looking at the example in the link shared above and the methods available here  which will help with your requirement 

Let me know if this helps

Anudeep
Soundar Raj PonpandiSoundar Raj Ponpandi
Dear AnuDeep,

Thanks for your quick response.

I followed your advice and created one standard approval process and triggering with controller. Please find the following apex class, Here i am not able to approve automatically and sending to next approver.
 
public class GD_QuoteApprovalController {
    
    PUBLIC STATIC FINAL STRING GD_ME_INFECTION_CONTROL ='Infection Control' ;
    PUBLIC STATIC FINAL STRING GD_ME_CWS ='CWS';
    PUBLIC STATIC FINAL STRING GD_ME_SURGERY ='Surgery';
    PUBLIC STATIC FINAL STRING GD_ME_GI_ET ='GI & ET';
    
    PUBLIC STATIC FINAL STRING GD_ME_DIALYSIS ='Dialysis';
    PUBLIC STATIC FINAL STRING GD_ME_IMAGING_SYSTEM ='Imaging System';
    PUBLIC STATIC FINAL STRING GD_ME_PHARMACY_AUTOMATION ='Pharmacy Automation';
    PUBLIC STATIC FINAL STRING GD_ME_CRITICAL_CARE ='Critical Care';
    
    @AuraEnabled
    public static GD_Quote__c getQuoteDetails(String quoteId){
        try{
            GD_Quote__c quote = new GD_Quote__c();
            List<User> approvalUsers = new List<User>();
            quote = [SELECT Id,GD_Status__c,OwnerId,GD_Quote_Margin__c,GD_Warranty_Years__c,GD_Has_FOC__c,
                     GD_Business_Unit__c,GD_Business_Unit__r.Name,GD_Total_In_AED__c,GD_Sales_Rep__r.ManagerId
                     FROM GD_Quote__c WHERE Id=: quoteId ];
            approvalUsers = [SELECT Id,Name FROM User WHERE userRole.Name =: Label.GD_ME_Division_Manager_Role_Name];
            User loggedInUser = [SELECT Id,Name,profile.name FROM User WHERE Id=:userInfo.getUserId()];
            string coordinator = loggedInUser.profile.name;
            system.debug('coordinator ' +  coordinator);
            if(approvalUsers.isEmpty()){
                throw new AuraHandledException('No Division manager assigned.');    
            }
            //if(quote.GD_Sales_Manager__c == '' || quote.GD_Division_Manager__c ==''){
            quote.GD_Sales_Manager__c = quote.GD_Sales_Rep__r.ManagerId;
            quote.GD_Division_Manager__c = approvalUsers.get(0).Id;
            //if(coordinator.contains('Coordinator')){
                quote.GD_Sales_Coordinator__c = loggedInUser.Id;
            //}
                update quote;
            //}
            return quote;
        }catch(Exception e){
            throw new AuraHandledException(e.getMessage());    
        }
    }
    
    @AuraEnabled
    public static void submitForApproval(GD_Quote__c quoteRecord,String approvalComments){
        try{
            List<Approval.ProcessSubmitRequest> approvalRequestList = new List<Approval.ProcessSubmitRequest>();
            String approverId;
            boolean toUpdate = false;
            system.debug('Business Unit Name '+quoteRecord.GD_Business_Unit__r.Name);
            if(quoteRecord.GD_Business_Unit__r.Name == GD_ME_SURGERY || quoteRecord.GD_Business_Unit__r.Name == GD_ME_INFECTION_CONTROL || 
               quoteRecord.GD_Business_Unit__r.Name == GD_ME_CWS || quoteRecord.GD_Business_Unit__r.Name == GD_ME_GI_ET || 
               quoteRecord.GD_Business_Unit__r.Name == GD_ME_DIALYSIS || quoteRecord.GD_Business_Unit__r.Name == GD_ME_IMAGING_SYSTEM || 
               quoteRecord.GD_Business_Unit__r.Name == GD_ME_PHARMACY_AUTOMATION || quoteRecord.GD_Business_Unit__r.Name == GD_ME_CRITICAL_CARE){
                toUpdate = true;
            }
            
            if(toUpdate){
                Approval.ProcessSubmitRequest req1 = new Approval.ProcessSubmitRequest();
                req1.setComments(approvalComments);
                req1.setObjectId(quoteRecord.Id); 
                approvalRequestList.add(req1);
                system.debug('approvalRequestList.size() > ' + approvalRequestList.size());
                if(approvalRequestList.size() >0){
                    Approval.process(approvalRequestList);
                } 
                ProcessInstance nodeId =  [SELECT  Id, TargetObjectId, (SELECT Id, StepNodeId, StepStatus FROM Steps)  FROM ProcessInstance WHERE TargetObjectId = :quoteRecord.Id limit 1];
                system.debug('nodeId ***' + nodeId);
            }
            
        }catch(Exception e){
            system.debug('EXCEPTION ******* '+e.getStackTraceString());
            throw new AuraHandledException(e.getMessage());    
        }
    }
    
}

Regards,
Soundar.​​​​​​​