We have a Email Sending feature from an object SBQQ__Quote__c. We need to update SBQQ__Quote__c object's one field from EmailMessage Trigger.

But while code using editor (Sublime or salesforce inline editor) the RelatedToId (EmailMessage Object) field is not accessible and giving RelatedToId field doesn't exist error.

Whenever I wants to run same query from Developer Console, it is not giving any error, and giving expected result. My Sample code is like these:

Id emailId = Id.valueOf('02s0m00000028eVAAQ');
for(EmailMessage emailMsg : [SELECT Id,ParentId,Incoming,RelatedToId FROM 
EmailMessage WHERE Id = :emailId ]) 
    System.debug('EmailMsg-Id : '+emailMsg.Id);
    System.debug('EmailMsg-Income : '+emailMsg.Incoming);
    System.debug('EmailMsg-Related : '+emailMsg.RelatedToId);
    System.debug('EmailMsg-Parent : '+emailMsg.ParentId);

These given code is running in Developer Console, but if i want to use the same code in my apex code using any editor, it is giving that RelatedToId fields doesn't exist.

RelatedToId // this field in select query is not accessible.
System.debug('EmailMsg-Related : '+emailMsg.RelatedToId);

Can any body give me some idea about the resolution?

2 Answers 2


Try upgrading the version of your class.

Often when any field/object is not available in Apex but in developer console, cause is the lower version of class where that functionality is unavailable.

  • WOW, Thanks a Lot. yes, earlier the class api version was 34.0. I just changed the api version to 41.0 ( the latest version). And it is working fine. Thanks Again Commented Dec 27, 2017 at 11:54

Also try to enable Enhanced Email (Setup -> Email -> Enhanced Email -> Enable)

  • Today you are totally correct! API Version is now way above 41.0.
    – TheShadow
    Commented Apr 6, 2023 at 8:24

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .