function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion

Test Email-to-Case with mass emails and EMailMessage trigger

We are working on an org where cases are generated via Email-to-Case and a trigger on EmailMessage is carrying out some processes. A batch job then in a 5 minute rhythm works on these generated cases and does some further processing.

Here my questions:
  1. How can we simulate that 100-1000 emails are sent to this Email-to-Case email address? Via Apex Script in the Anonymous Code Block?
  2. The problem that we face with the apex script is that when we try sending 10 emails via Messaging.SingleEmailMessage - everything works fine the EmailMessage Objects have a parentId reference to the case which is also visible in the EmailMessage trigger. But when we try sending about 100 emails via Messaging.Email the EmailMessage object has also the parentId case reference but the parentId is null in the trigger

Thanks in advance for your responses and time
NagendraNagendra (Salesforce Developers) 

May I suggest you simply mock 100 EmailMessages as if they came from Email2Case and insert in a test method

Note: by the time the real Email2Case builds these objects, they will have a parentID so you'll need to mock Cases aforehand

thnx for your response - doing it through test is also an option but we wanted to simulate the real go through. Additionally - my guess is that the parentId is populated after the EmailMessage Trigger has been completed. Because if i do a select in my after insert method - the EmailMessage Objects are there but the parentId is null .... and if i do an export after all is through i can see the parentId has been magically populated