+ Start a Discussion

Inputfield support on wrapper class member variables

Does anyone have a method for getting a wrapper class "object" to emulate an sObject, so that the fields have inputfield support on a VF page?
I have searched, and it appears you need to implement an instance of an object, and bind the fields to the objects fields, but I can't seem to make this work.  Anyone ever do this?  have sample code?

My actual requirement is this, I have a custom object and want to have a VF page for creation and editing.  one section of the page is a grid with multiple rows of the same data (in the object they are labeled like this: valA1,valB1,valC1,valA2,valB2,valC2 etc).  A is a string field, B is a lookup and C is a date.

Any thoughts or suggestions would be greatly appreciated.


Ron HessRon Hess
here is an example


defining a wrapper.

note his comment:
To access the wrapper class, I just used {!product.line.UnitPrice} for the standard Salesforce or {!product.UnitPrice} for the value in my custom wrapper class to get the formatting that I wanted.

this will give your InputField a valid sobject to display
Thanks Ron,  I did figure out something like this, but still have an issue I can't determine.  My intent is to have custom class members get used in other places in my code, and just use the sObject reference to support the inputfield reference. Here is my class, maybe you can tell me what I am doing wrong.   I would like to use the cval members everywhere in my apex code, and only use the copp field members for the VF page.  I think  I am missing something in the way my setter and getter are defined:

public class valueprops{
     public String cvalDesc; 
     public ID cvalwho;
     public Date cvalwhen;
     public OpportunityProfile__c copp; 
     public valueprops(){
      copp=new OpportunityProfile__c();
     public void setcopp(OpportunityProfile__c opc){
     public OpportunityProfile__c getcopp(){
      return copp;
     public String getcvalDesc(){
      return copp.valdesc1__c;
     public void setcvalDesc(String v){
      copp.valDesc1__c = v;
     public ID getcvalwho(){
      return copp.valwho1__c;
     public void setcvalwho(ID vid){
      copp.valwho1__c = vid;
     public Date getcvalwhen(){
      return copp.valwhen1__c;
     public void setcvalwhen(date vdate){
      copp.valwhen1__c = vdate;


Ron HessRon Hess
i think i need to see how you are calling this class from apex code, and how you are binding to it from VF code. 

then i can offer suggestions.
I don't think that I am doing it correctly at all.
Step back to my original scenario.
I have a custom object that has a section that includes 3 rows of similar data, a description (string), a Contact (lookup) and a date.(Date)
In the object, they look like this: desc1,contact1,date1,desc2,contact2,date2,desc3,contact3,date3
my goal was to display them on a VF page in a table grid view for both viewing and editing.
My original thought was to array them using a wrapper class, and creating a list of that class that could be accessed by a datatable on my page
The problem with this is that I lose access to the inputfield functionality (the lookup for example, and the datepicker).
I guess I could build my own table using the original fields, but I was hoping to figure this out, in case I needed the functionality in other cases.
So, my goal was to somehow access a wrapper class object in a way that the fields still had their inputfield properties, but could be manipulated in my apex code, and ultimately update one final instance of my custom object.

My thought was do do something like this:

protected valueProps vp1;
protected valueProps vp2;
protected valueProps vp3;
private List<valueProps> cvalProps = new List<valueProps>{};

public class valueprops{
     public String cvalDesc {get; set;} 
     public ID cvalwho {get; set;}
     public Date cvalwhen {get; set;}
     public OpportunityProfile__c copp {get; set;} 
     public valueprops(){
      copp=new OpportunityProfile__c();
    public void setvalProps(List<valueProps> cvalProps){
      cvalDesc =cvalProps.vp1.copp.valDesc1__c;
         cvalwho =cvalProps.vp1.copp.valwho1__c;
         cvalwhen =cvalProps.vp1.copp.valwhen1__c;
         cvalDesc =cvalProps.vp2.copp.valDesc1__c;
         cvalwho =cvalProps.vp2.copp.valwho1__c;
         cvalwhen =cvalProps.vp2.copp.valwhen1__c;
         cvalwhen =vp3.copp.valwhen1__c;
    public List<valueprops> getvalProps(){
     return cvalProps;


Then somehow use those primitive datatypes to populate values in my real record to update.

Any suggestions would be greatly appreciated!

David Roberts 4David Roberts 4
see https://developer.salesforce.com/forums/?id=906F00000008m5wIAA