I am trying to create a custom visualforce page that saves new opportunity contact roles to an opportunity. I am having trouble creating the first step of listing out all contacts that relate to that account. The error I am getting is...

Save error: Could not resolve the entity from value binding '{!u.contact}'. can only be used with SObjects, or objects that are Visualforce field component resolvable.

I do not understand why I am receiving this error. u.contact should resolve to a Contact object, which is an sObject. Am I misunderstanding something?

Here is my code...


public class ChooseContactController 
    public String accountId = ApexPages.currentPage().getParameters().get('accountId');
    public Account account { get; set; }
    public List<UnfundedOpportunityContactRole> unfundedOpportunityContactRoles { get; set; }

    public ChooseContactController() 
        unfundedOpportunityContactRoles = new List<UnfundedOpportunityContactRole>();
        List<Contact> contacts = [SELECT Id, Name FROM Contact WHERE AccountId =: accountId];
        account = [SELECT Id, Name FROM Account WHERE Id =: accountId];

        for(Contact c: contacts) 
            unfundedOpportunityContactRoles.add(new UnfundedOpportunityContactRole(c, 'The Man'));

    public void Save() {}
    public void Create() {}

    public class UnfundedOpportunityContactRole
        public Contact contact { get; set; }
        public String role { get; set; }

        public UnfundedOpportunityContactRole() { }

        public UnfundedOpportunityContactRole(Contact contactParam, String roleParam)
            this.contact = contactParam;
            this.role = roleParam;

VF page

<apex:page controller="ChooseContactController">
  <apex:form >
    <apex:pageBlock title="Choose a contact" mode="edit">
      <apex:pageBlockButtons >
        <apex:commandButton action="{!create}" value="New"/>
        <apex:commandButton action="{!save}" value="Save"/>
        <apex:pageBlockSection title="{!account.Name}">
          <apex:dataTable value="{!unfundedOpportunityContactRoles}" var="u">
            <apex:column headerValue="Contact">
              <apex:inputField value="{!u.contact}" />
            <apex:column headerValue="Role">
              <apex:inputField value="{!u.role}" />

1 Answer 1


The apex:inputField value u.contact must correspond to an SObject field. That is typically done by u being a reference to an SObject and contact being an SObject field name. For your example, that SObject field would be lookup field to Contact.

apex:inputField requires meta data such as the field label that is only available from an SObject field; your class field can't provide that metadata.

Try changing your Visualforce to:

<apex:column headerValue="Contact">
    <apex:inputField value="{!u.contact.Id}" />
<apex:column headerValue="Role">
    <apex:inputText value="{!u.role}" />
  • That helps me understand why I am getting that error. Thanks.
    – Mr. Ant
    May 5, 2014 at 22:00

You must log in to answer this question.

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