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
Nikita Yadav 17Nikita Yadav 17 

ActivityID is not Getting generated

Hello experts,

Need Urgent Help.

Whenever i insert records in bulk in EmailMessage Object,the activityId is not getting generated.I dont unsderstand why it is happening? Please tell what is going on and why?

NOTE :: I am inserting Records without RelatedToId and ParentId.

Thank you!!
SwethaSwetha (Salesforce Developers) 
HI Nikita,

You cannot set the ActivityId on the EmailMessage as it would throw: Insert failed. First exception on row 0; first error: INSUFFICIENT_ACCESS_OR_READONLY, You cannot edit this field: [ActivityId]

Since the Email message has no relatedToId field which you generally use to directly link it to any desired record, it is probably showing null.Note that an EmailMessage record will be created with it's ActivityId set to the Task-Id.

Recommend reviewing: https://salesforce.stackexchange.com/questions/224492/how-to-use-an-apex-email-service-to-store-emails-on-a-record-exactly-as-salesfor

If this information helps, please mark the answer as best. Thank you
 
Nikita Yadav 17Nikita Yadav 17

@Swetha

First of all Thank you for replay.

I am migrating EmailMessage Records which are related to contacts.Obviously I can't set RelatedToId or ParentId Field,but whenever I insert records in EMailMessage, system does not creating Task that is why I am getting ActivityId Field null.But I dont Understand why it is happening?Do you have any idea?

Already tried this  https://help.salesforce.com/articleView?id=000352303&type=1&mode=1 
but same problem.