+ Start a Discussion
wesnoltewesnolte 

Bug in abbreviated getters and setters?

Hello

 

I'm getting a strange error with abbreviated getters and setters.. but when I write the full getters/setters the code works perfectly.

 

First, the code that works.

 

Extension

public class helper { SessionData__c s; public helper(ApexPages.StandardController controller) { s= new SessionData__c(); } public SessionData__c getS(){ return s; } public void setS(SessionData__c value){ s= value; } public void add(){ insert s; } }

 

Apex page

 

<apex:page standardController="SessionContainer__c" extensions="helper"> <!-- Begin Default Content REMOVE THIS --> <h1>Congratulations</h1> This is your new Page: session <!-- End Default Content REMOVE THIS --> <apex:pageblock> <apex:pageBlockSection> <apex:form > <apex:inputField value="{!S.name}"/> <apex:commandButton action="{!add}" value="Save"/> </apex:form> </apex:pageBlockSection> </apex:pageblock> </apex:page>

 

 

As I said, the above code works. Now should I change the controller extension so:

 

public class helper { SessionData__c s{get;set;} public helper(ApexPages.StandardController controller) { s= new SessionData__c(); } public void add(){ insert s; } }

 

 

I get the following error:

 

Could not resolve the entity from <apex:inputField> value binding '{!S.name}'. inputField can only be used with SObject fields.

 

Any ideas?

Best Answer chosen by Admin (Salesforce Developers) 
aalbertaalbert
Just taking a shot here , but what if you add the keyword "public" to the variable declaration within the controller:
SessionData__c s{get;set;}

All Answers

aalbertaalbert
Just taking a shot here , but what if you add the keyword "public" to the variable declaration within the controller:
SessionData__c s{get;set;}
This was selected as the best answer
wesnoltewesnolte
Look at that! It worked.. big up to you.