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
sylar20sylar20 

Email going twice when triggered

The challenge is that the email is going twice.

 

following is the code for sending email (part of class)

 

    Messaging.SingleEmailMessage mail = new Messag​ing.SingleEmailMessage();
    String[] toAddresses = new String[] {c.Client_​Email_Address__c};
    if(c.Client_Email_Address_Optional__c != null)​{
    String[] toAddresses2 = new String[] {c.Client​_Email_Address_Optional__c};
    mail.setCcAddresses(toAddresses2);}
    mail.setToAddresses(toAddresses);
     EmailTemplate et = [SELECT id FROM EmailTempl​ate WHERE developerName = 'Dispute_Notification'];
    mail.setTemplateId(et.id);
    mail.setTargetObjectId(c.ContactId);
    mail.setwhatId(c.Id);
    mail.saveAsActivity = true;
    mail.setOrgWideEmailAddressId('0D2S0056674CiI'​);
    Messaging.sendEmail(new Messaging.SingleEmailM​essage[] { mail });

chris_centrachris_centra

i'd add some debugging and make sure that the trigger isn't being called twice (because of another trigger, workflow, etc). 

chris

Ankit AroraAnkit Arora

Hi sylar20,

 

Please make sure this part of your code is not running in  a loop.

 

Thanks

Ankit Arora

Blog | Facebook | Blog Page

hgarghgarg

Check your email settings:

From the let menu follow : Personal Setup --> Email--> Uncheck the Automatic Bcc on this screen

 

I faced the same issue and get solved in this way, let me know if it workd for you.