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
jfitz1959jfitz1959 

How would I go about searching for a particular Person Account that has a matching email address?

Apex Documentation shows this when selecting for 'person account' objects:

SELECT Name, SobjectType, IsPersonType FROM RecordType WHERE SobjectType='Account' AND IsPersonType=True

 

A) I don't know where to go from there (adding 'and email=joe@blow.com' throws an error)

B) if I used this method it would seem to be a two step process...there must be a more efficient 'select' statement to accomplish this in one step?

Best Answer chosen by Admin (Salesforce Developers) 
MattLacey.ax1065MattLacey.ax1065

Wow, I completely misread before, modified the query without thinking, and added the accounts fields to the RecordType query!!

 

Have a crack with this (may or may not be Email/PersonEmail - can't remember off the top of my head right now!).

 

SELECT Id, Name FROM Account WHERE RecordType.SobjectType = 'Account' AND RecordType.IsPersonType=True and PersonEmail='joe@blow.com'

 

All Answers

vishal@forcevishal@force

If your error is about an invalid field when you add email, then try this :

 

where PersonEmail = 'xyz@xyz.com' 

 

 

jfitz1959jfitz1959

Tried your suggstion ~ I get this error message:

Error: Compile Error: No such column 'personemail' on entity 'RecordType'. If you are attempting to use a custom field, be sure to append the '__c' after the custom field name. Please reference your WSDL or the describe call for the appropriate names. at line 6 column 30

 

List <account> accts = [SELECT Name, SobjectType, IsPersonType FROM RecordType WHERE SobjectType='Account' AND IsPersonType=True and personemail='joe@blow.com'];

MattLacey.ax1065MattLacey.ax1065

Wow, I completely misread before, modified the query without thinking, and added the accounts fields to the RecordType query!!

 

Have a crack with this (may or may not be Email/PersonEmail - can't remember off the top of my head right now!).

 

SELECT Id, Name FROM Account WHERE RecordType.SobjectType = 'Account' AND RecordType.IsPersonType=True and PersonEmail='joe@blow.com'

 

This was selected as the best answer
jfitz1959jfitz1959

This actually compiled (don't know if it works yet though), but here's a follow on. What if I want all the fields in the record, similar to SQL 'select * from ...'?

MattLacey.ax1065MattLacey.ax1065

Then you have to list them all ;)

 

There is no equivalent of SQL's * in SOQL. You can use describe information on the objects to get the list of fields and build up the query using dynamic SOQL, but if you're just trying to save a bit of time now that will actually take you longer than listing the fields :)