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...
Controller
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:pageBlockButtons>
<apex:pageBlockSection title="{!account.Name}">
<apex:dataTable value="{!unfundedOpportunityContactRoles}" var="u">
<apex:column headerValue="Contact">
<apex:inputField value="{!u.contact}" />
</apex:column>
<apex:column headerValue="Role">
<apex:inputField value="{!u.role}" />
</apex:column>
</apex:dataTable>
</apex:pageBlockSection>
</apex:pageBlock>
</apex:form>
</apex:page>
Attribution to: Mr. Ant
Possible Suggestion/Solution #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>
<apex:column headerValue="Role">
<apex:inputText value="{!u.role}" />
</apex:column>
Attribution to: Keith C
This content is remixed from stackoverflow or stackexchange. Please visit https://salesforce.stackexchange.com/questions/34401