Selecting custom fields of "who" object using SOQL gives no such column error

StackOverflow https://stackoverflow.com/questions/18822281

  •  28-06-2022
  •  | 
  •  

Pregunta

I am looking for select custom fields of "who" object using SOQL in slaesforce:

As I am testing following SOQL, its working fine.

Select t.Who.FirstName, t.Status From Task t Where t.ActivityDate = TODAY AND t.Who.Type = 'Lead'

but while add any custom field of lead object(who object here) in select statement, as mentioned following query, its give error as

No such column 'LeadExtraInfo__c' on entity 'Name'.

even LeadExtraInfo field exist into Lead object

Select t.Who.FirstName, t.Who.LeadExtraInfo__c t.ActivityDate From Task t Where t.ActivityDate = YESTERDAY AND t.Who.Type = 'Lead'
¿Fue útil?

Solución

The Who and What relationships on Task are not normal relationships -- they are polymorphic. This means that they can refer to different types of objects.

In the case of Who, it can refer to a Lead or a Contact. As such, you can only get to a limited subset of the fields in the relationship, namely the ones mentioned in this doc page.

To get to other fields on Lead, you'll have to query the Task first to get its WhoId, then query Lead where the Id equals that WhoId value to get those other fields.

Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow
scroll top