You need to sign in to do that
Don't have an account?
CotralLabWebDev
How to retrieve an Event Contact Email through the Who object ?
Hi,
I need to retrieve the Contact data associated with an Event.
I have an SOQL query that looks like this :
The thing is, it is not null in the database, nor when I do something like :
So why would I be able to retrieve the last name and first name of the contact, but not the email ? What should I do to achieve this, without having to send another query ?
Thanks
I need to retrieve the Contact data associated with an Event.
I have an SOQL query that looks like this :
SELECT Id, WhatId, Subject, ActivityDate, StartDateTime, Type , Who.Id, Who.LastName, Who.Email, Who.Type , Owner.Id, Owner.LastName, Owner.Email FROM Event WHERE Subject IN ('Rendez-vous') AND Type IN ('PE') AND Who.id != null AND Who.Type = 'Contact' AND WhatId IN ('006...')Every queried field is properly returned, except one : Who.Email is always null.
The thing is, it is not null in the database, nor when I do something like :
SELECT Id, LastName, FirstName, Email FROM Contact WHERE id = 'Contact Id'Where "Contact Id" is the "Who.Id" from the first query.
So why would I be able to retrieve the last name and first name of the contact, but not the email ? What should I do to achieve this, without having to send another query ?
Thanks
This is working as designed. You will not get any value (null) for who.Email.
Some fields are relationship fields, which means they can be used to get information about a related object. And some of those relationship fields are polymorphic fields. A polymorphic field is one where the related object might be one of several different types of objects.
To determine what kind a field is, call describeSObjects() on the object and examine the properties for the field.
#1) If relationshipName is not null, the field is a relationship field.
#2) If, in addition, namePointing is true, then the field is polymorphic.
Example of a Polymorphic Field: -
The OwnerId field of the Event object has the following properties:
#1) relationshipName = Owner
#2) namePointing = true
#3) referenceTo = Calendar, User
This means it is a polymorphic field. Owner could be a Calendar, or a User. For example, you can use the following SOQL query:
SELECT Id, Owner.Name FROM Event WHERE Owner.Type = 'User'
Please refer to the below documentation regarding that: -
https://developer.salesforce.com/docs/atlas.en-us.soql_sosl.meta/soql_sosl/sforce_api_calls_soql_relationships_and_polymorph_keys.htm
If this solution helps, Please mark it as best answer.
Thanks,
All Answers
This is working as designed. You will not get any value (null) for who.Email.
Some fields are relationship fields, which means they can be used to get information about a related object. And some of those relationship fields are polymorphic fields. A polymorphic field is one where the related object might be one of several different types of objects.
To determine what kind a field is, call describeSObjects() on the object and examine the properties for the field.
#1) If relationshipName is not null, the field is a relationship field.
#2) If, in addition, namePointing is true, then the field is polymorphic.
Example of a Polymorphic Field: -
The OwnerId field of the Event object has the following properties:
#1) relationshipName = Owner
#2) namePointing = true
#3) referenceTo = Calendar, User
This means it is a polymorphic field. Owner could be a Calendar, or a User. For example, you can use the following SOQL query:
SELECT Id, Owner.Name FROM Event WHERE Owner.Type = 'User'
Please refer to the below documentation regarding that: -
https://developer.salesforce.com/docs/atlas.en-us.soql_sosl.meta/soql_sosl/sforce_api_calls_soql_relationships_and_polymorph_keys.htm
If this solution helps, Please mark it as best answer.
Thanks,
There is one detail I'm not sure I understand though: do I have to make another query to get this email, or is there a way to get it directly with the first query?
As this is salesforce functionality and limitation. You have to use another SOQL query to get the contactc emails based on the contact id.
If this solution helps, Please mark it as best answer.
Thanks,
I still think that not allowing this field (email) to be retrieved while others are (first and last name) is an arbitrary and quite impractical decision.Especially since the Who of an Event can only be a Contact or a Lead, and both of these objects have an Email field.
But I have my answer, thanks for your help !