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?


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.

| improve this answer | |
  • 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 – Yousuf Zaman Dec 27 '17 at 11:54

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

| improve this answer | |

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.