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
vikas  malikvikas malik 

How to reference Case owner in Apex on New Case Creation

I have written some code - which sends an email and includes some of the field values for a new case, but it leaves off the lookup field values (in other words, when I reference the Account.BillingCity, Contact.Email, etc.), I get null values.

From what I can tell, it looks like lookup values are inserted on new record creation after the case is inserted (and after the "After Insert" triggers have fired - this is why I get null values when the fields are referenced in my sent email.
Best Answer chosen by vikas malik
Gaurav NirwalGaurav Nirwal
for (Case myCase : [SELECT Id, Subject, CreatedDate, Product_Code__c,
Owner.Name, Account.Name, Account.BillingCity,
Account.BillingStateCode, Contact.Name,
Contact.Email, Contact.Phone                     
FROM Case WHERE
 Id IN :Trigger.new]) {

All Answers

SonamSonam (Salesforce Developers) 
If I understand the issue right...you will have to query for the values of these fields: Account.BillingCity, Contact.Email, etc. because these values are not present and only the Id's of contact and account are there on the case.
Gaurav NirwalGaurav Nirwal
for (Case myCase : [SELECT Id, Subject, CreatedDate, Product_Code__c,
Owner.Name, Account.Name, Account.BillingCity,
Account.BillingStateCode, Contact.Name,
Contact.Email, Contact.Phone                     
FROM Case WHERE
 Id IN :Trigger.new]) {
This was selected as the best answer