function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion

Help with Dynamic Binding

I'm trying to use dynamic binding on the OpportunityLineItem based on some fields the user can specify, however, the binding does not seem to work when saving.  Below is some code snippets.  Was wondering if anyone can tell me what I'm doing wrong.

Controller Extension


public class MyControllerExt {
  public List<MyModel> modelList {get; set;}
  public List<String> oliFieldsList {get; set;}

  public MyControllerExt(ApexPages.StandardController controller) {
    modelList = new List<MyModel>();

  public void addToModel() {
    modelList.add( new MyModel() );





public class MyModel {
  public OpportunityLineItem oli {get; set;}

  public MyModel() {
    oli = new OpportunityLineItem();


VF Page



  <table cellpadding="2px" width="100%">
    <apex:repeat value="{!modelList}" var="model">
      <apex:repeat value="{!oliFieldsList}" var="field">
          <apex:inputField value="{!model.oli[field]}"/>



The VF page will properly display two text input fields, one for Quantity and one for Price.  The Quantity has a red line next to it to signal that it's required so at least I know it's binding correctly to the page on load.  When I enter some values in the text inputs and go to save by clicking on a button, the values that I enter do not get recoginzed.

This is what my save looks like:


public PageReference save() {
  List<OpportunityLineItem> olisToUpsert = new List<OpportunityLineItem>();

  for (MyModel m : modelList) {
    m.oli.PricebookEntryId = [some price book entry id];
    m.oli.OpportunityId = [some opportunity id];

upsert olisToUpsert;
return new PageReference ('/' + opportunityId); }