in my controller i have a variable Custom_obj_c c with a getter method that is called in the constructor. In my visualforce, how do i access the fields of c?

sorry, i've got a brain freeze right now.


Custom_Obj__c c must be public with a getter and setter, like this:

public Custom_Obj__c c { get; set; }

It can then be accessed through the binding c:

|improve this answer|||||
  • I'm getting the error: Error: Unknown property 'BytecodeApexObject.myField__c' – PartOfTheOhana Aug 1 '13 at 18:43
  • We're probably going to need to see some source code, then. Can you show us your controller and page? – sfdcfox Aug 1 '13 at 18:49
  • i got it to work.. is there a way to customize the getter? – PartOfTheOhana Aug 1 '13 at 18:53
  • You can use a getter body, like: public custom_obj__c c { get { if(c==null) c = new custom_obj__c(); return c; } set; } – sfdcfox Aug 1 '13 at 18:55
  • that works, thanks! can you explain why i need to write the getters and setters like that? usually i define the object public obj__c c; and then have getter and a setter later in the code as "seperate methods – PartOfTheOhana Aug 1 '13 at 19:09

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.