+ Start a Discussion
Yogesh BiyaniYogesh Biyani 

Controller Extension for a custom object

I have a custom object Contact_Preference__c and I have created a controller extension as shown below 
public class myContactPreferenceControllerExtension {

    private final Contact_Preference__c cp;
    
    public myContactPreferenceControllerExtension(ApexPages.StandardController stdController) {
        this.cp = (Contact_Preference__c)stdController.getRecord();
    }

    public String getGreeting() {
        return 'Hello ' + cp.name + ' (' + cp.id + ')';
    }
}

When I try to call the getGreeting method in the Visualforce page  as shown below ​
<apex:page standardController="Contact_Preference__c" extensions="myContactPreferenceControllerExtension">
    <apex:outputText id="test" value="{!getGreeting}"/>
</apex:page>
the developer console shows the following problem 

Unknown property 'Contact_Preference__cStandardController.getGreeting' 

What am I doing wrong? 

 
Narender Singh(Nads)Narender Singh(Nads)
Hi Yogesh,
 Change line 3 like this:

 <apex:outputText id="test" value="{!Greeting}"/>

Let me know if it helps.
Thanks!
Ajay K DubediAjay K Dubedi
Hi Yogesh,

You have to pass the method in this way because method is of string return type so it will automatically use get,set in return type.

<apex:page standardController="Contact_Preference__c" extensions="myContactPreferenceControllerExtension">
<apex:outputText id="test" value="{!Greeting}"/>
</apex:page>

Thank you
Ajay Dubedi