function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
youji37youji37 

invoke Approval in trigger

I want to invoke a approval in trigger, I only know the approval name like 'Unit cost less than Field Min', but don't know how to invoke it in trigger.

 

trigger autoApproveTrigger on Quote__c(after update,after insert) {
    
    for (Quote__c a : Trigger.new) {
        
        if(a.Quoted_Cost_Unit_Price__c >= a.Field_Min1__c){
            //Unit cost_less_than_Field_Min.Quote(a.Id);
        
        }else{
            //do nothing for other record type case.
        }
    }
}
can someone help on it?
Best Answer chosen by Admin (Salesforce Developers) 
hisrinuhisrinu

You can invoke using the following steps, make sure that the approval process is in active state.

 

                        Approval.ProcessSubmitRequest req1 = new Approval.ProcessSubmitRequest();
                        req1.setComments('Submitting request for approval.');
                        req1.setObjectId(mr.id);
                        Approval.ProcessResult result1 = Approval.process(req1);