You need to sign in to do that
Don't have an account?
Yogesh 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
When I try to call the getGreeting method in the Visualforce page as shown below
Unknown property 'Contact_Preference__cStandardController.getGreeting'
What am I doing wrong?
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?
Change line 3 like this:
<apex:outputText id="test" value="{!Greeting}"/>
Let me know if it helps.
Thanks!
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