0 votes
1 view
in Salesforce by (11.9k points)

I am trying to get the Contact/Lead email from the Task object using SOQL (I am creating an interface in PHP to back up messages with a specific subject). Here is my query right now:

SELECT Subject,Who.FirstName,Who.LastName,Who.Email,Who.Phone,Description FROM Task

This works/doesn't throw an error and gives me results, but Who.Email is always empty (and, coincidentally Who.Phone is as well, but it is not very important for this). If I try just using Email I get an error that the field doesn't exist, which is weird because Email is under Task Fields as a standard field.

I have also tried several google searches with no sort of assistance found.

1 Answer

0 votes
by (31.6k points)
edited by
This is because the WhoID and WhatID fields of the task are polymorphic (i.e. they can point to many different kinds of objects) you can't just query relationships through them like you can for normally-related objects. Instead, you'll have to do 2 SOQL queries, the first one, to get the Task information and the second one, to get the info from the Contact or Lead that the Who is pointing to.
Welcome to Intellipaat Community. Get your technical queries answered by top developers !


Categories

...