You need to sign in to do that
Don't have an account?
Richard Clarke (Artisan)
Why would SendEmail not log to activity history in production but work in a sandbox?
The following code sends an email to a Contact using a template.
It works perfectly in a sandbox (email sent/received AND logged into activity history).
In our production work the email is sent/received but the activity history/task is not added.
I've tried coding the block a few ways as there are different ways of using SendEmail but in all cases I get the same outcome.
The code is running inside a future method.
If I run the code in anonyous apex it works as expected in production.
Any idea why an SendEmail call would not log activity history and not throw any exceptions?
Messaging.SingleEmailMessage message = new Messaging.SingleEmailMessage();
message.setTemplateId( emailTemplateId );
message.setSaveAsActivity( true );
message.setOrgWideEmailAddressId( XXXXXXId );
message.setTargetObjectId( contacts[0].Id );
message.toAddresses = new String[] { contacts[0].Id };
Messaging.SingleEmailMessage[] messages = new List<Messaging.SingleEmailMessage> {message};
Messaging.SendEmailResult[] results = Messaging.sendEmail(messages);
It works perfectly in a sandbox (email sent/received AND logged into activity history).
In our production work the email is sent/received but the activity history/task is not added.
I've tried coding the block a few ways as there are different ways of using SendEmail but in all cases I get the same outcome.
The code is running inside a future method.
If I run the code in anonyous apex it works as expected in production.
Any idea why an SendEmail call would not log activity history and not throw any exceptions?
Messaging.SingleEmailMessage message = new Messaging.SingleEmailMessage();
message.setTemplateId( emailTemplateId );
message.setSaveAsActivity( true );
message.setOrgWideEmailAddressId( XXXXXXId );
message.setTargetObjectId( contacts[0].Id );
message.toAddresses = new String[] { contacts[0].Id };
Messaging.SingleEmailMessage[] messages = new List<Messaging.SingleEmailMessage> {message};
Messaging.SendEmailResult[] results = Messaging.sendEmail(messages);
https://developer.salesforce.com/docs/atlas.en-us.api.meta/api/sforce_api_objects_asyncapexjob.htm