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
iKnowSFDCiKnowSFDC 

Outbound messaging class generating email address twice

I'm sending an outbound email message and the code I'm using to select the email address is adding the address to the string array twice. I'm not seeing what this happening - any ideas? Ultimately, I need to be able to pass in either the personEmail to the string OR the Secondary_Email__c but am having this issue with the email address being passed in twice that I have to solve first. 

 

 

//some other code logic
//

public pageReference submitEmail(){

     
String[] toAddresses = new String[]{
                    [SELECT id, PersonEmail 
                     FROM Account 
                     WHERE id = :ApexPages.currentPage().getParameters().get('id')].PersonEmail
};

system.debug('email addresses are>>>>'+toAddresses);

emailHelper.sendEmail(toAddresses, acct.id, emailSelected, recipient.id); 


// Email Helper Class

Global class emailHelper {

public static void sendEmail(string[] toAddresses, id acct, String tempName, id recipient) {

    String usersName = userInfo.getFirstName()+' '+userInfo.getLastName();

  	//New instance of a single email message
   Messaging.SingleEmailMessage mail = new Messaging.SingleEmailMessage();
 
	// Who you are sending the email to
   mail.setToAddresses(toAddresses);

   // The email template ID used for the email
   mail.setTemplateId([SELECT id, Name, Secondary_Email__c FROM EmailTemplate WHERE Name = :tempName].id);
          
   mail.setWhatId(acct);    
   mail.setBccSender(false);
   mail.setUseSignature(true);
   mail.setReplyTo([SELECT id, Email FROM User WHERE id = :UserInfo.getUserId()].email);
   mail.setSenderDisplayName(usersName);
   mail.setSaveAsActivity(true); 
   mail.setTargetObjectid(recipient); 
 
Messaging.sendEmail(new Messaging.SingleEmailMessage[] { mail });

    }  
}

 

Thanks for your help!