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
Calin Fintzi 13Calin Fintzi 13 

Relatedtoid SOQL references

RelatedtoID on Email message and WhatID on Task both allow many different objects to be referenced. Is it possible to querty into the reference table of the object type that's in the field?

EX: If I know that the field contains a reference to a contract could I do the following:

SELECT Id, TextBody, MessageDate
FROM EmailMessage
WHERE RelatedTo.BalanceDue = 0 AND RelatedTo.Type = '#*@$'
SwethaSwetha (Salesforce Developers) 
HI Calin,
Can you provide more clarity on what you meant by  "query into the reference table of the object type that's in the field" so I can suggest better? If possible, another SOQL example and what is the error you are seeing

Related: https://salesforce.stackexchange.com/questions/224298/different-between-relatedtoid-vs-parentid-in-emailmessage
https://salesforce.stackexchange.com/questions/143528/emailmessage-query-returns-no-such-column
Thanks