1

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>&nbsp;</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
2
  • 1
    Did you create a case with salesforce?
    – RedDevil
    May 16, 2019 at 6:53
  • Yes, they are actively investigating and will continue to update here. If you have two orgs on the different releases, I'd be curious to see if someone else can reproduce.
    – S.B.
    May 16, 2019 at 14:03

1 Answer 1

0

This is a known issue:

In the use case above, has to do with .setWhatId method. Resolved in Summer '19. My workaround will be a custom setting control to determine whether or not to hard create an email message object.

https://success.salesforce.com/issues_view?id=a1p3A000000FmX1QAK

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .