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
Mihir Kumar 15Mihir Kumar 15 

How to write test class that uses MessagingSession object


I have written a trigger on ContentDocumentLinkobject to cover the below scenario:

1. If there is a ContentDocumentLink record created with a ContentDocumentId & Entity ID is of MessagingSession object, and
2. MessagingSession record referred in Entity ID has a case linked to it then

A new ContentDocumentLink record is created to link the ContentDocumentId and the case related to MessagingSession record referred in EntityID.

Now, I don't know how to write the test class of the same as I am not finding way to create MessagingSession record. Kindly help.
ShirishaShirisha (Salesforce Developers) 
Hi Mihir,


Can you please check the below document for the metadata details of the MessagingSession Object which will help you in creating or linking the Objects while writing the test class:

Kindly let me know if it helps you and close your query by marking it as best answer so that it can help others in the future.

Warm Regards,
Shirisha Pathuri
Prachi Arya 13Prachi Arya 13

Hi Mihir,
I have a same requirement.I have written a trigger on MessagingSession Object. I need to write test class for it where I need to create MessagingSession object records. Can you please share your code if you were able to resolve it.

Hi Prachi, Mihir,

Can you let us know how you wrote the test class for MessagingSession, what was your approach?