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 problem

 I use following code to invoke a approval process in trigger, the approval process will send an email to the owner's manager for approval, now the problem is when I update of insert the record, the approval will run twice, it will send two email to the owner's manager, but I only invoke it once as you can see in the 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){
             
             Approval.ProcessSubmitRequest req1 = new Approval.ProcessSubmitRequest();
             req1.setComments('Submitting request for approval.');
             req1.setObjectId(a.id);
             Approval.ProcessResult result1 = Approval.process(req1);
             
        }else{
            //do nothing for other record type case.
        }
    }
    
}

 

 

Best Answer chosen by Admin (Salesforce Developers) 
kerwintangkerwintang

Is it possible that you have updated or inserted twice? or performed an insert then an update?

 

best regards,

Kerwin