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
Peter KempPeter Kemp 

When referencing account.name with inputField, you must select isPersonAccount in your SOQL query

I have been following the cookbook and would like to add fields to edit objects on my visual force page.  I have used the following code:

 

 

<apex:pageBlockSectionItem > <apex:outputLabel value="Name"/> <apex:inputField value="{!account.name}"/> </apex:pageBlockSectionItem>

 and the apex:

 

public Account getaccount() { return [select id, salutation, name from Account where id = :System.currentPageReference().getParameters().get('id')]; }

 

 it brings up the error:

When referencing account.name with inputField, you must select isPersonAccount in your SOQL query

 I have tried using SOQL that selects isPersonAccount = true but this doesn't seem to fix the proble, what is the error asking for?

 

Thanks

 

Pete


 

 

 

 

 

Best Answer chosen by Admin (Salesforce Developers) 
dchasmandchasman

public Account getaccount() {
return [select id, salutation, name, isPersonAccount from Account where id =
:System.currentPageReference().getParameters().get('id')];
}

 

Is there any reason you are not using the Standard Controller for Account that will take case of all of this for you automatically?

All Answers

dchasmandchasman

public Account getaccount() {
return [select id, salutation, name, isPersonAccount from Account where id =
:System.currentPageReference().getParameters().get('id')];
}

 

Is there any reason you are not using the Standard Controller for Account that will take case of all of this for you automatically?
This was selected as the best answer
Peter KempPeter Kemp

Thanks Doug,

 

That fixed it. The reason I'm not using the standard controller is that I'm using a selection of objects from all over the shop on this page.  I understand that if you are using a standard controller this limits your interaction with other objects.

 

thanks again!

 

Pete

dchasmandchasman
Using the standard controller (SC) does not limit your interaction in any way - in fact in many situations it will automatically create the correct heirarchical SOQL query to retrieve related objects. If you find that the base functionality of the SC does not do everything you need a better option than dropping to a custom controller would be to leverage a controller extension that lets you mix in your custom code into the SC but still gives you the benefits of using the DC.