You need to sign in to do that
Don't have an account?
register trigger email as an activity
I could crack logging a trigger email as an activty but it sends the email twice and it also sends the email to contact email id too??
I just wanna send an email to CLient_Email_Address__c
Any idea?
Messaging.SingleEmailMessage mail = new Messaging.SingleEmailMessage();
String[] toAddresses = new String[] {c.CLient_Email_Address__c};
mail.setToAddresses(toAddresses);
mail.setTargetObjectId(c.ContactId);
mail.setwhatId(c.Id);
EmailTemplate et = [SELECT id FROM EmailTemplate WHERE developerName = 'Completion_Notification'];
mail.setTemplateId(et.id);
mail.saveAsActivity = true;
Messaging.sendEmail(new Messaging.SingleEmailMessage[] { mail });
If you set the what id, the default behavior is to send an email to the standard email associated with what id (lead, contact or user) and unfortunately there is no easy way to override that. If you are particular about sending email to an email address from a custom field and still log it as an activity, you could leave saveAsActivity as false and then then log the activity yourself (An insert of task record with who id, what id, subject, description and status set). This would require some heavy lifting on your part. But I am afraid this is the best way to address both requirements.
All Answers
If you set the what id, the default behavior is to send an email to the standard email associated with what id (lead, contact or user) and unfortunately there is no easy way to override that. If you are particular about sending email to an email address from a custom field and still log it as an activity, you could leave saveAsActivity as false and then then log the activity yourself (An insert of task record with who id, what id, subject, description and status set). This would require some heavy lifting on your part. But I am afraid this is the best way to address both requirements.
The challenge now is that the same email is going twice.
following code for sending email (part of class)
Messaging.SingleEmailMessage mail = new Messaging.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 EmailTemplate 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.SingleEmailMessage[] { mail });
Chek you email settings:
Follow the left setup menu :- Personal setup -->Email --> My Email Settings --> Uncheck Automatic BCC option
Hope it works for you.