You need to sign in to do that
Don't have an account?

default 'toAddress' in Messaging.SingleEmailMessage() API
Hello All,
I have written a code for sending email through APEX.
I am using a custom field for saving original Email address from Email field of Contact object. And masking the original Email. So my original email field value is 'DuXXX@XXXXX.XXX' and Custom is like 'Dummy@gmail.com'.
When i am sending the email using Messaging.SingleEmailMessage() API the when i receive email in 'to address' ther are both the values (from custom email field and standard one.)
How can i remove the standard one from there as i have only added 1 value from custom field in code.
Or it is standard salesforce behaviour.
Thanks,
Nivedita
I have written a code for sending email through APEX.
I am using a custom field for saving original Email address from Email field of Contact object. And masking the original Email. So my original email field value is 'DuXXX@XXXXX.XXX' and Custom is like 'Dummy@gmail.com'.
When i am sending the email using Messaging.SingleEmailMessage() API the when i receive email in 'to address' ther are both the values (from custom email field and standard one.)
How can i remove the standard one from there as i have only added 1 value from custom field in code.
Or it is standard salesforce behaviour.
Thanks,
Nivedita
String[] toAddresses = new List<String>{contact.CustomFieldAddress};
email.setToAddresses(toAddresses);
Hope it helps, if it does mark it as solved.
Thanks
Thank you for your reply but i am doing this and i don't know how in email there are two addresses. Although i am adding only one custom field value.
My Code : Also , Below is the To Address that i received.
Thanks
Can you post the code before String email =null; as i want to know the loop you are using . Is it a query loop or just iteration of list?
Thanks
There is no loop or iteration. I am sending single email.
Also 'email' is a variable that i used in my code.
Thanks,
Nivedita
This is what i did in my org:-
Basically when i commented mail.setTargetObjectId then it was not fetching standard email of contact and i added it in Email_Address__c.
Hope it helps, if it does mark it as solved.
Thanks