0

I'm querying contact email field in apex class and saving the return record inside a list. but when I debug the list queried then it does not show the email field. Below is the SOQL which I'm using with the debug log :-

listOfContact = [Select Name,recordtype.name, Account.Name,email from Contact where accountid = :Accountobj.id and recordtype.name='abc'];

Here is the debug log which I see :-

listOfContactAssociatedWithAccount(Contact:{Name=ee, Id=0030214569874563210, RecordTypeId=012541258963547812}, Contact:{Name=Apple- 13, Id=0030214569874563854, RecordTypeId=012541258963544571})

Why does it happen and what is solution for this.

  • 3
    Are you sure that the contacts have an email inserted in that field? – Carlos Naranjo Nov 7 '19 at 16:41
  • does the running user have FLS on Contact.Email? – cropredy Nov 7 '19 at 19:34
0

Run a SOQL to find out if they have emails inserted on that field or the amount of records that are under that search.

List<Contact> contacts = [
SELECT Name, Recordtype.Name, Account.Name, Email 
FROM Contact 
WHERE accountid = :Accountobj.id 
AND RecordType.Name='abc'];
System.debug(contacts.size());

Make sure that you write your query correctly. If you get that the size is above 0. Use a for loop to see the value of those records with an Email.

for(Contact con : contacts) {
  System.debug('This is the Id and Email for the Contact with an email address: ' + 'Id' + con.Id + 'Email: ' + con.Email);
}

This way you can find out if there are Contacts under you soql criteria and you can find which ones have an email.

In your debug, are you sure that the list of contacts is the correct one?

  • yes, all the returning records contain email value in the database which I can see in the query editor after running the same query. And also in the debug I can see all the fields queried but cannot see the email field . – Jitesh Goel Nov 7 '19 at 16:52
  • It looks to me that those records don't have a email address: – Carlos Naranjo Nov 7 '19 at 16:55

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.