1

Why I'm getting this error I do have the method name called SelectedContact, is that a required to thing to use getSelectedContact?

enter image description here

Public List<Contact> SelectedContact()
{
    return LoadContactByAccountId;
}


<apex:pageblock id="selectedContactList" title="Selected Contact">
    <apex:pageblocktable id="selectedContactList" value="{!SelectedContact}" var="selContact">
            <apex:column headervalue="Last Name">
                <apex:outputfield value="{!selContact.LastName}">
            </apex:outputfield></apex:column> 
            <apex:column headervalue="First Name">
                <apex:outputfield value="{!selContact.FirstName}">
            </apex:outputfield></apex:column>  
            <apex:column headervalue="Email">
                <apex:outputfield value="{!selContact.Email}">
            </apex:outputfield></apex:column>  
            <apex:column headervalue="Phone">
                <apex:outputfield value="{!selContact.Phone}">
            </apex:outputfield></apex:column>  
  </apex:pageblocktable>

1 Answer 1

1

Visualforce has exactly two types of method calls it can directly invoke: getter/setter and actions. Getters and setters are required for assignTo and value attributes, and actions are required for action attributes. Getters and setters come in two varieties, inline or functions. The function variety, which is what you're trying to use, must start with get or set, for getters and setters, respectively. You will not include the get or set part of the function name when calling it through an expression. So, to answer your question directly, you must use the getSelectedContact form of the function name for what you're trying to do.

2
  • Thanks for explanation and since I'm new, how would you use inline getter/setter an example would be great 1+
    – Nick
    Jul 14, 2015 at 18:08
  • @AbuHamzah That uses the abbreviated form, which looks a bit like this: public Contact[] selectedContact { get { return LoadContactByAccountId; } }. There's more details about this form in the docs, so I'd suggest you take a look and read up. Of course, you could just make a public Contact[] selectedContact { get; set; } variable, and assign the query directly to that variable: selectedContact = [SELECT ... FROM Contact ...];
    – sfdcfox
    Jul 14, 2015 at 18:28

You must log in to answer this question.

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