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.