In a data migration context from a Salesforce organization to another one, a requirement we have is to transfer the 'EmailMessage' from an organization to another.

As they are the main interaction tool with customers in the service process, the emails should appear in reverse chronological order in the related list on the case page layout for performance purposes (Poping the stack algorithmically speaking).

The issue encounters from the characteristics of the related list : it's ordered by the email's created date by default and not the message date.

Assuming this, we explored the following workarounds:

  • Configuring the list's ordering field : KO, cf. Salesforce success community
  • Writing on the CreatedDate field : KO, the set audit fields permission on profile & configuration don't allow to write on the email's created date field
  • Ordering by Message Date the emails before sending the batch to Salesforce : KO, the records are not treated sequentially whereas they should be...

Hereafter, a demonstration by example:

Extract Emails from source Organization:

  • Email 1 ; Message Date : 26/04/2017

  • Email 2 ; Message Date : 25/04/2017

Order them by message date chronologically =>

  • Email 2 ; Message Date : 25/04/2017

  • Email 1 ; Message Date : 26/04/2017

Send them to Salesforce using the REST API:

Expected Behavior:

  • Email 2 gets imported (row 1)

  • Email 1 gets imported (row 2)

Expected Result in related list case:

  • Email 1 displayed first (most recent)

  • Email 2 displayed after (oldest)

Observed Result :

  • Email 2 displayed first (whereas it's the oldest)

  • Email 1 displayed after (whereas it's most recent)

My questions:

  • On the configuration side, is there a workaround we didn't explore to change the displaying order of the emails in the case related list ? (We would rather not do some custom development)
  • On the data preparation/ordering side, is there some other out of the box attempts you would advice (like trying to base ourself on the sequential behavior of the API) ?

2 Answers 2


Good morning everyone, Good news : managed to find a workaround.

The mistake that I made was to base myself on the sequential treatment of the batch without taking in account the fact that the records are processed asynchronously (the apex processing time is not taken in account before going to an other record).

The solution to this problem is to simulate a synchronous behavior in which we wait for the insertion of the previous Email to be done before sending the next one.

Here-after, an example describing this behavior:


  • Email1; MessageDate : 01/05/2017
  • Email2; MessageDate : 02/05/2017


  • Email1's insertion starts
  • As Email1 is being treated (not inserted yet), Email2's insertion starts
  • Email2's insertion end (apex processing time) before Email1's

Result: Email2's has been created before Email1 => Not inserted in the right order.


You need to give your user "Set Audit Fields upon Record Creation" permissions in order to allow the user to Set audit fields, such as Created By, Last Modified By, and Created Date when you create a record (API only i.e Importing Tools) with Data Loader in order to make the Created Date writable.

See the following Knowledge Articles for more: 000171151, 000213290, and 000005202. You no longer need to file a support case with Salesforce as was necessary in the past.

  • Unfortunately this doesn't work on the email message object which is a special object as said in the second KO workaround expected. Commented May 3, 2017 at 8:16

You must log in to answer this question.

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