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
Toyota System 3Toyota System 3 

PersonEmail field not accessible on creation of Person Account record

Apex tests have started to fail where we assert PersonEmail field is populated.

Replicated the issue in Execute Anonymous via the following code:
Account customer = new Account();
customer.RecordTypeId=[select id from RecordType where sObjectType = 'Account' and DeveloperName = 'Consumer' limit 1].Id;
customer.lastname='Test Account';
customer.personEmail = 'test.testAAA@example.eu';
customer.PersonHomePhone = '061386212';
insert customer;

customer= [select id, name, firstname, lastname, personEmail, PersonHomePhone, IsPersonAccount  from account where id=:customer.id];
system.debug(logginglevel.info,'Account = '+customer);
system.debug(logginglevel.info,'Account.personEmail = '+customer.personEmail);
system.debug(logginglevel.info,'Account.PersonHomePhone = '+customer.PersonHomePhone);
The debug logs show PersonHomePhone populated but PersonEmail is null.  The Person Email field is visible on the record after creation via the UI and via a query in Developer Console.

After a random period of time the same query in Execute Anonymous starts to return the PersonEmail field.

I have also witnessed the field being populated if I query it via a list, but empty if I specify an Id in the where clause.

Query list:
SOQL1

Query with Id:
SOQL2

Very strange behaviour.

There seems to be some slow running process that means PersonEmail is not immedeatly available to query (even though it is visible via the UI).

Please help.
 
Best Answer chosen by Toyota System 3
Toyota System 3Toyota System 3
This has now been confirmed as a Known Issue.

https://trailblazer.salesforce.com/issues_view?id=a1p4V000002BQKcQAO
 

All Answers

Rodney Birch 10Rodney Birch 10
This is very strange for any database:
  • Write a record with an email field
  • Read the same record by ID - email is blank
  • Read the same record by ID some time later - email is visible
You'll never be able to deploy test code that check the email addresses.

How is it possible to cause this as a developer?
If the email field is blanked by a trigger then it isn't stored. What is coming back 10 mins later to update the same record and guesses the correct email value correctly every time.
Toyota System 3Toyota System 3
This has now been confirmed as a Known Issue.

https://trailblazer.salesforce.com/issues_view?id=a1p4V000002BQKcQAO
 
This was selected as the best answer