1

I Currently have a visualforce page where I want a user to be able to select a existing person account or create a new one.

I am getting the error: Attribute value in apex:inputField must contain only a formula expression that resolves to a single controller variable or method

Visualforce

<apex:page controller="TestController">
<apex:inputField  value="TestValue">{!pa.name}</apex:inputField>
</apex:page>

Apex

public class TestController {
  public Account pa{get;set;}
  public void AdminController() {    
    pa = [select name from Account where isPersonAccount  =true limit 1];  
  } 
}
2

The easiest way to achieve this is by creating a custom field that has a lookup field to Account with a lookup filter to only show Person Accounts (Use record type to filter or isPersonAccount boolean). You can add this field on any object, I would prefer to add this to a custom object.

Then all you need is bind the field to the inputField.

public class TestController {
 public CustomObject__c pa{get;set;}
 public TestController() {    
     pa = new CustomObject__c();  
 } 
}

_ vf page

<apex:page controller="TestController">
  <apex:inputField value="{!pa.Account__c}"></apex:inputField>
</apex:page>

Here Account__c is a lookup field on the Custom Object to Account with lookup filter to the Person Account.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.