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
gaurav.sfdcgaurav.sfdc 

Access Contact.Email from Case object

If I run below query in query editor it runs fine and give all fields but in Apex or execute anomynous it gives just CaseNumber, ContactId, ID.

List<sObject> lst = [SELECT CaseNumber, Contact.FirstName, Contact.LastName, Contact.Email, ContactId, Id FROM Case  WHERE ID IN('500o0000001OaQsAAK','500o0000001OaR0AAK','500o0000001OaQeAAK') and Contact.Email <> null order by CaseNumber limit 10000];
System.debug(lst);

Any help would be appreciated
 
Best Answer chosen by gaurav.sfdc
zoranszorans
Hi gaurav,

not sure about the explanation why it is not showing when you put it in this form but you can always see results by accessing every individual list row from a for loop. Also please notice when you have more data showing whole list or map from System.debug is limited on somwhere around 20 records as I remeber it is always better way to show your exact data row by row regardeles to ammount.
 
List<Case> lst = [SELECT CaseNumber, Contact.FirstName, Contact.LastName, Contact.Email, ContactId, Id FROM Case  WHERE ID IN('500o0000001OaQsAAK','500o0000001OaR0AAK','500o0000001OaQeAAK') AND Contact.Email <> null order by CaseNumber limit 10000];

for(Case sO:lst){
	System.debug('Case Number '+sO.CaseNumber+' Contact FName '+sO.Contact.FirstName+' Contact LName '+sO.Contact.LastName+' Contact Email '+sO.Contact.Email+' Contact ID '+sO.ContactId);
}


 

All Answers

zoranszorans
Hi gaurav,

not sure about the explanation why it is not showing when you put it in this form but you can always see results by accessing every individual list row from a for loop. Also please notice when you have more data showing whole list or map from System.debug is limited on somwhere around 20 records as I remeber it is always better way to show your exact data row by row regardeles to ammount.
 
List<Case> lst = [SELECT CaseNumber, Contact.FirstName, Contact.LastName, Contact.Email, ContactId, Id FROM Case  WHERE ID IN('500o0000001OaQsAAK','500o0000001OaR0AAK','500o0000001OaQeAAK') AND Contact.Email <> null order by CaseNumber limit 10000];

for(Case sO:lst){
	System.debug('Case Number '+sO.CaseNumber+' Contact FName '+sO.Contact.FirstName+' Contact LName '+sO.Contact.LastName+' Contact Email '+sO.Contact.Email+' Contact ID '+sO.ContactId);
}


 
This was selected as the best answer
gaurav.sfdcgaurav.sfdc
Thanks zorans , I got it .. parsing to case gives the result..