1

I am getting this response 'Field is not writeable: EmailMessage.RelatedToId'

Email trigger helper method is the following:

public static void parseEmailSubjectForLeadRelation(List<EmailMessage> emailList){
        system.debug('Entered parseEmailSubjectForLeadRelation');
        List<EmailMessage> emList = new List<EmailMessage>();
        string leadId;
        for(EmailMessage email : emailList) {
            system.debug('email == ' + email.TextBody + ' / ' + email.ParentId);
            if(email.Incoming == true && email.ParentId != null && email.TextBody != null) {
                if(email.TextBody.contains('reference:')){
                    email.RelatedToId = email.TextBody.substringBetween('reference:{', '}');
                    emList.add(email);
                }
            }
        }
        update emList;
}

This is being called on AfterInsert. I have seen another similar question that was fixed by updating the api version of the apex class which i have already tried. I have also double checked that enhanced email is enabled in this org.

2

According to the documentation for the EmailMessage Object, this field can only be set on insert not update

  • 1
    Wow ! thank you Bryan, i knew there was some rule i was just not realizing. I believe i can take it from here. Thanks! – Logie C Nov 22 '19 at 18:56

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.