3

I want to know LastName and PersonEmail from account. So I made sql like this:

[SELECT AccountNumber, LastName, PersonEmail, Phone, BillingPostalCode FROM Account]

But it doesn't work properly and errors.

No such column 'LastName' on entity 'Account'. 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. How can I get LastName from Account Object?

0

3 Answers 3

2

Is Person Accounts feature enabled in your salesforce org?

For LastName, PersonEmail and other related fields, ensure field visibility is enabled.

If you are querying person account fields from Account object then put a where clause IsPersonAccount=True in your query.

1
  • The IsPersonAccount=true is not required, but of course the fields will be null for business accounts. Also, FLS isn't the issue. Person Accounts is not enabled for the org.
    – sfdcfox
    Jun 18, 2017 at 16:20
0

Person Accounts combine both Contact and Account where some Contact Info is also displayed in the Account Detail page. In a person account, the Contact.Name field is displayed as the Account.Name field. To get a separate FirstName and LastName, you need to query the Contact object.

Your query would need to look more like

[SELECT LastName, Email, Phone, PostalCode, AccountId from Contact]

If you query it from Account, you'd need to do a subquery to get the Contact's LastName.

[SELECT AccountNumber, Phone, BillingPostalCode (SELECT LastName, Email FROM CONTACT) FROM Account] 

You might optionally want to add WHERE clause like: WHERE Account.NAME contains Contact.LastName

2
  • It's not necessary to query the contact for standard fields.
    – sfdcfox
    Jun 18, 2017 at 16:20
  • @sfdcfox I agree if it's a standard field. That also requires a query to use IsPersonAccount=true. In which case, there are a number of Contact fields that then become available as IsPersonAccount fields that can be queried directly from Account. In either case, the fields will still exist under Contact.
    – crmprogdev
    Jun 18, 2017 at 21:52
0

If person account is enabled in your Org you will have a record type called 'Person Account' when you try to create a new account.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .