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
Gemini@WorkGemini@Work 

Unable to get the "email" field of a Person-Account via Apex

In the Org I'm currently working with, they have Person-Accounts enabled.

 

In Person-Accounts, "email" is a valid field in the Account object.  I've been able to use the email field in Page layouts, and update the field via the standard UI -- but I am unable to query or write to the field in Apex.

 

Instead, I get an error message that "email" is not a recognized field for the Account object:

 

 

Is there a method for accessing the "email" field on Person-Accounts?

Best Answer chosen by Admin (Salesforce Developers) 
dmsx2oddmsx2od

The field is Account.PersonEmail.

 

(Hint: Use Data Loader to do a full SOQL "describe" of the object by telling it to export all fields and then just doing a copy/paste on the generated SOQL.)

(Hint2: Use Excel Connector to describe the object and pull the field names from that.)

 

Great question, especially since it provides a place to remind all that custom PersonAccount fields end with __pc, which is just plain odd! :)

All Answers

werewolfwerewolf

A person account is an agglomeration of an Account and a Contact.  Try

 

Select email From Contact where AccountId=<your account ID>

dmsx2oddmsx2od

The field is Account.PersonEmail.

 

(Hint: Use Data Loader to do a full SOQL "describe" of the object by telling it to export all fields and then just doing a copy/paste on the generated SOQL.)

(Hint2: Use Excel Connector to describe the object and pull the field names from that.)

 

Great question, especially since it provides a place to remind all that custom PersonAccount fields end with __pc, which is just plain odd! :)

This was selected as the best answer
JPSeaburyJPSeabury

Thanks, David Schach (and Kingsley, too, for the Twitter assist).

 

PersonEmail was the way to go:

 

 

facEmail = [select id, PersonEmail
                  from Account
                  where id = :System.currentPageReference().getParameters().get('fac1')];

 

The field names that I looked at in the DataLoader this afternoon were not the same ones I looked at in the same DataLoader last night at 2:00am.  :-D