Automatically email invoices with a trigger

Automatically send an email when a Quote is Accepted

Example of calling a function when the Status value of the Quote object becomes Accepted:

trigger Quote on Quote (after update) {
    
    public List<Quote>      newObjList  {get; set;}
    public Map<Id, Quote>   oldObj      {get; set;}

    newObjList = (List<Quote>)Trigger.new;
    oldObj = (Map<Id, Quote>)Trigger.oldMap;
    if (trigger.isAfter && trigger.isUpdate){   
        for(Quote qu : trigger.new){   
            if (qu.Status == 'Accepted' && qu.Status != oldObj.get(qu.id).Status){
                // Pass the template Id and recordId as parameters
                String templateId = DocumentCustomController.getTemplateId();
                DocumentCustomController.triggeredSavePdf(qu.Id, templateId);
            }
        }        
    }
    
}

Example function to get a template ID from the template name:


Example function to send an email to the user:


Example of saving a Document Template as a PDF

Last updated

Was this helpful?