You need to sign in to do that
Don't have an account?
Daniele Serra
Why is Case.ContactEmail field is NULL?
Hi community, I'm working with case object. This is my code:
After insert the case, i can visualize caso.ContactId, but ContactEmail and SuppliedEmail stay null. I can visualize contat.email different from null. Someone can explain to me why ContactEmail don't retrieve the email from the Contact?
Thank you so much.
Case caso= new Case(); Contact contatto=[SELECT Id, Name, Email FROM Contact where Account.id =: uli.B2WISU__Account__c limit 1]; System.debug(contatto.Email); caso.ContactId=contatto.id; caso.Status = 'New'; caso.Description = 'TestDescription'; insert caso; System.debug(caso.ContactId); System.debug(caso.ContactEmail); System.debug(caso.SuppliedEmail);
After insert the case, i can visualize caso.ContactId, but ContactEmail and SuppliedEmail stay null. I can visualize contat.email different from null. Someone can explain to me why ContactEmail don't retrieve the email from the Contact?
Thank you so much.
Please try below code. Please let me know if it helps you.
Case caso = new Case();
Contact contatto = [SELECT Id, Name, Email FROM Contact where Account.id = : uli.B2WISU__Account__c limit 1];
System.debug(contatto.Email);
caso.ContactId = contatto.id;
caso.Status = 'New';
caso.Description = 'TestDescription';
// as supplied email won't be updated automatically.
caso.SuppliedEmail= contatto.Email;
insert caso;
//After insert only Id is updated in the existing object that's why you are not getting below Value.
System.debug(caso.ContactId);
System.debug(caso.ContactEmail);
System.debug(caso.SuppliedEmail);
// to get other you will have to query again as below.
Case newCaseCreated = [Select Id, ContactId, ContactEmail, SuppliedEmail from Case where Id = : caso.Id];
System.debug(newCaseCreated.ContactId);
System.debug(newCaseCreated.ContactEmail);
System.debug(newCaseCreated.SuppliedEmail);
Regards,
Pawan Kumar
All Answers
Please try below code. Please let me know if it helps you.
Case caso = new Case();
Contact contatto = [SELECT Id, Name, Email FROM Contact where Account.id = : uli.B2WISU__Account__c limit 1];
System.debug(contatto.Email);
caso.ContactId = contatto.id;
caso.Status = 'New';
caso.Description = 'TestDescription';
// as supplied email won't be updated automatically.
caso.SuppliedEmail= contatto.Email;
insert caso;
//After insert only Id is updated in the existing object that's why you are not getting below Value.
System.debug(caso.ContactId);
System.debug(caso.ContactEmail);
System.debug(caso.SuppliedEmail);
// to get other you will have to query again as below.
Case newCaseCreated = [Select Id, ContactId, ContactEmail, SuppliedEmail from Case where Id = : caso.Id];
System.debug(newCaseCreated.ContactId);
System.debug(newCaseCreated.ContactEmail);
System.debug(newCaseCreated.SuppliedEmail);
Regards,
Pawan Kumar
Try to run the following code;
Hope it helps!
Please let me know if it works for you.
Regards,
Pawan Kumar