You need to sign in to do that
Don't have an account?
ketan mehta
Send mail and record as activity history for an object issue.
Hi,
I am tring to send email from trigger and required to log as Activity History for an opportunity. I am setting mail.targetObjectId as opportunityId. I am getting an exeption like : INVALID_TYPE_FOR_OPERATION, Only Users, Contact or Lead allowed for targetObjectId. I read some articles on Google and mentioned that it is not possible. Is there any way to achieve the same?
Thanks in advance.
Ketan
I am tring to send email from trigger and required to log as Activity History for an opportunity. I am setting mail.targetObjectId as opportunityId. I am getting an exeption like : INVALID_TYPE_FOR_OPERATION, Only Users, Contact or Lead allowed for targetObjectId. I read some articles on Google and mentioned that it is not possible. Is there any way to achieve the same?
Thanks in advance.
Ketan
Thanks for guiding towards right path. Finally I am able to achieve the same as below. Apart from setting the targetObjectId, we need to set mail.setWhatId value to the object id.
Messaging.SingleEmailMessage mail = new Messaging.SingleEmailMessage();
String[] toAddresses = new String[] {'xxxxx@yahoo.co.in'};
mail.setToAddresses(toAddresses);
mail.setBccSender(false);
mail.setWhatId('0069000000LKxxx');//OpportunityId
mail.setTargetObjectId('00390000012nwww'); //ContactId
mail.setSaveAsActivity(true);
mail.setSubject('test mail');
mail.setPlainTextBody('hi there');
Messaging.sendEmail(new Messaging.SingleEmailMessage[] {mail});
Regards,
Ketan Mehta
All Answers
Thanks for guiding towards right path. Finally I am able to achieve the same as below. Apart from setting the targetObjectId, we need to set mail.setWhatId value to the object id.
Messaging.SingleEmailMessage mail = new Messaging.SingleEmailMessage();
String[] toAddresses = new String[] {'xxxxx@yahoo.co.in'};
mail.setToAddresses(toAddresses);
mail.setBccSender(false);
mail.setWhatId('0069000000LKxxx');//OpportunityId
mail.setTargetObjectId('00390000012nwww'); //ContactId
mail.setSaveAsActivity(true);
mail.setSubject('test mail');
mail.setPlainTextBody('hi there');
Messaging.sendEmail(new Messaging.SingleEmailMessage[] {mail});
Regards,
Ketan Mehta