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
Kevin Chiles 930Kevin Chiles 930 

Email Trigger Firing twice

Hello!

I have an Email trigger that seems to be firing twice.  I cannot for the life of me figure out why.  Basically the trigger is picking up a template and a the attachments associated to a custom objects record and emailing it to a team.  This for some reason is firing 2 emails instead of one.  Its driving me mad!
 
trigger Send_TechDocs_Cloud on Sales_Handoff_Activity__c (after update) {



for(Sales_Handoff_Activity__c SHA : trigger.new){
    if (SHA.TAD_Status__c == 'TAD Complete' && SHA.Cloud__c==True && Trigger.oldMap.get(Sha.Id).TAD_Status__c != Trigger.newMap.get( Sha.Id ).TAD_Status__c ) {
   // && SHA.TAD_Status__c!=Trigger.oldMap.get(sha.id).TAD_Status__c
   
    //Retrieve Email template
     EmailTemplate et=[Select id from EmailTemplate where name=:'Cloud Tad Complete'];
     
     
    //Create email list
        List<Messaging.SingleEmailMessage> emails = new List<Messaging.SingleEmailMessage>();

       //Create attachment list
       List<Messaging.EmailFileAttachment> efalist = new List<Messaging.EmailFileAttachment>();
       
       contact c =[select id, email from Contact where Email=:'kevin.chiles@megapath.com' limit 1];
       //Create message
       
       Messaging.SingleEmailMessage singlemail = new Messaging.SingleEmailMessage();
        //add template
       singleMail.setTemplateId(et.Id);              
        //set target object for merge fields
        singleMail.setTargetObjectId(c.Id);
        singlemail.setwhatId(SHA.Id);       
        //set to save as activity or not
        singleMail.setSaveAsActivity(false);
         
         
        //add address's that you are sending the email to
        String []ToAddress= new string[] {'ash@megapath.com' }; 

        //set addresses
        singlemail.setToAddresses(toAddress);
        
        
            //add mail
                emails.add(singleMail);
        
        {
Help me Obi Wan, you're my only hope

Chiles
    
Nayana KNayana K
https://help.salesforce.com/articleView?id=000133752&language=en_US&type=1
Kevin Chiles 930Kevin Chiles 930
So I would just throw that at the top of my code before I get it started?  Or do I need to nest it within the code?

Thank you for the quick response!!!

Kevin