You need to sign in to do that
Don't have an account?
stop sending email to setTargetobjectId in single email message
Hi ,
I am writing single email message to code to send emails. I am dynamically constructing toAddresses to send emails. The code is working fine and sending email to toAddresses and setTargetobjectid.
I don't want to send email to setTargetobjectId. is there any way to stop sending email to setTargetobjectid?
Thanks
Siva.
I am writing single email message to code to send emails. I am dynamically constructing toAddresses to send emails. The code is working fine and sending email to toAddresses and setTargetobjectid.
I don't want to send email to setTargetobjectId. is there any way to stop sending email to setTargetobjectid?
Thanks
Siva.
setTargetObjectId is mandatory if you are using setTemplateId in your code.
EmailTemplate Emailtemplate=[SELECT Description, Body, Id, Name, BrandTemplateId, Markup, NamespacePrefix, TemplateStyle, Subject,
TemplateType FROM EmailTemplate where name=:'Brigade CPprofile Email RejectInfo'];
system.debug('$$$$$$$$$$$$$$$$'+Emailtemplate.id);
Messaging.SingleEmailMessage message = new Messaging.SingleEmailMessage();
String[] toAddresses = new String[] {usr.email};
string messageBody ;
message.setTemplateId(Emailtemplate.id);
// message.setTemplateId('00Xf0000000QJCi');
message.setTargetObjectId(usr.ContactId);
message.setWhatId(CPprofileObj.Id);
message.saveAsActivity=false;
message.setToAddresses(toAddresses);
Messaging.sendEmail(new Messaging.SingleEmailMessage[] { message });
Email sending perfectly but email is sending to both targetobjectid and toAddresses etc.
I don't want to send email to targetobjectid.
Thanks & Regards
Siva.
Were you able to find a solution to this? I'm having the same problem. I'd like to send an internal email as part of an exception process; I want to use a template and merge certain data from the contact record I'm handling, but I definitely don't want to send the email to the contact.
Any advice you can offer would be greatly appreciated!
Deb
You can remove toAddresses() from the block it will solve the issue , As it is not a required property for SingleEmailMessages.
So once toAddresses is removed , settargetobjectid() will take care of the email being sent.
Thanks
Jyoti
you can block setTargetObject by using setTreatTargetObjectAsRecipient(treatAsRecipient) boolean method
message.setTreatTargetObjectAsRecipient(false);
Thanks, i was also facing same problem but using setTreatTargetObjectAsRecipient(false); it solve
Also, Siva, you should mark this as solved :)