I am using the following logic to send emails. Enhanced email is activated on both orgs and so is Email-to-case.
In the sandbox (Summer '19), executing this method results in an email message correctly related to the id. These are dynamic variables in the actual class, but for the sake of the test below I hardcoded them in specific to the instances they reside in. The outcome is still the same. Executing the same in production (Spring '19) does not result in an email message object and does not relate to the case. However emails are received from both environments.
Messaging.SingleEmailMessage message = new Messaging.SingleEmailMessage();
List<String> stringOfAddresses = new List<String>();
stringOfAddresses.add('[email protected]');
message.setSubject('Test Subject');
message.setToAddresses(stringOfAddresses);
message.setOrgWideEmailAddressId('0D20c0000XXXXXX');
message.setWhatId('5000t0000XXXXXX');
message.setHtmlBody('<span style="font-family: sans-serif;">' + (('updatedBody'.replaceAll('<p><br></p>', '')).replaceAll('<p> </p>', '').replaceAll('class="ql-editor"','')) + '</span>');
Messaging.SingleEmailMessage[] messages = new List<Messaging.SingleEmailMessage> {message};
Messaging.SendEmailResult[] results = Messaging.sendEmail(messages);
if (results[0].success) {
CustomObject__c cObject = new CustomObject__c();
cObject.text1__c = 'Test';
cObject.relatedCase__c = '5000t0000XXXXXX';
cObject.text2__c = ('test').left(131072);
insert cObject;
}
else {
}
Update:
This is increasingly looking like a bug with Spring 19 that is fixed Summer 19, however there are no related release notes to indicate a change in this method.
I completed the following test cases where Email Message object is consistently created in Summer and not in Spring.
Email-to-case NOT ENABLED without project deployment changeset components (Apex Execute Anonymous Test)
- Spring Org - Creates a Task
- Summer Org - Does not create a Task
Email-to-case ENABLED with project deployment changeset components (Apex Execute Anonymous Test)
- Spring Org - Does not create an Email Message Object or Task
- Summer Org - Creates an Email Message Object
Email-to-case ENABLED with project deployment changeset components (Through our Apex Class & Visualforce Page)
- Spring Org - Does not create an Email Message Object or Task
- Summer Org - Creates an Email Message Object