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
KtobenerKtobener 

Controller Extension for VF to save multiple OLI's within repeat tag

I'm creating a visualforce page for a client that allows the organization to view their opportunities and assosiated opportunity products with in-line edit abilities for the opportunity products. I've made the page successfully, but I need a controller extension to update the opportunity products, and this is where I've been running into trouble. Having never built an extension, I've been trying to customize examples from the help and the community boards but nothing has worked yet. I would really appreciate some help from somebody!

 

 

 

 

 

Page:

 

<apex:page standardcontroller="Opportunity" extensions="OLIControllerextensionTEST" recordSetVar="Opportunity" tabStyle="opportunity" sidebar="true">
<apex:form id="theForm">
<apex:pageBlock >
      <apex:pageBlockButtons location="top">
         <apex:commandButton value="Save" action="{!save}"/>
         <apex:commandButton value="Cancel" action="{!cancel}"/>
        </apex:pageBlockButtons>
  <apex:pageBlockTable value="{!Opportunity}" var="o">
      <apex:column >         
          <h3>Opportunity Information for Opportunity:&nbsp;&nbsp;</h3> <apex:outputLink value="/{!o.id}" id="theLink">{!o.name}</apex:outputLink>
          <br/><br/>
            <table border="0" >
            <tr>
            <th>Opportunity Name</th>
                <th>Account Name</th>
                <th>Amount</th>
                <th>Close Date</th>
                <th>Stage Value</th>
            </tr>
            <tr>
            <td><apex:inputField value="{!o.name}"/></td>
                <td>{!o.Account.BillingCity}</td>
                <td>{!o.Amount}</td>
                <td><apex:outputText value="{0,date,MM-dd-yyyy}"><apex:param value="{!o.CloseDate}"/></apex:outputText></td>
                               
        <td>{!o.StageName}</td>
             </tr>
       </table>
          <br/><br/>
          <h2>Related Opportunity Products:</h2>
            <table border="0">
            <tr>
              <th align="left">Product&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</th>
              <th>Date</th>
              <th align="left">Quantity</th>
              <th align="left">Sales Price</th>
              <th align="left">Total Price</th>
              <th>Revenue Model</th>
              <th>Bundle</th>
              <th>Duration (months)</th>
              <th>Number Resources</th>
            </tr>
            <apex:repeat value="{!o.OpportunityLineItems}" var="oli">
            <tr>
              <td><apex:inputField value="{!oli.PricebookEntry.Name}"/></td>
              <td><apex:inputField value="{!oli.ServiceDate}"/></td>
              <td><apex:inputField value="{!oli.Quantity}"/></td>
              <td><apex:inputField value="{!oli.PricebookEntry.UnitPrice}"/></td>
              <td><apex:inputField value="{!oli.TotalPrice}"/></td>
              <td><apex:inputField value="{!oli.Revenue_Method__c}"/></td>
              <td><apex:inputField value="{!oli.Bundle__c}"/></td>
              <td><apex:inputField value="{!oli.Advisory_Duration_Months__c}"/></td>
              <td><apex:inputField value="{!oli.Number_Staff__c}"/></td>
            </tr>
            </apex:repeat>          
            </table>
            <br/><br/>                
      </apex:column> 
  </apex:pageBlockTable>

    <apex:panelGrid columns="2">
      <apex:commandLink action="{!previous}">Previous</apex:commandlink>
      <apex:commandLink action="{!next}">Next</apex:commandlink>
    </apex:panelGrid>
   
</apex:pageBlock>
</apex:form>
</apex:page>

 

 

 

 

This is the controller extension I got to work on another visualforce page with the opp id in the url and an opportunity standard controller, but I would love if I could find a way to work this into a visualforce page with multiple opps/olis on it!

 

 

Controller Extension:

 

public class OLIControllerextensionTEST {


private Opportunity opp;
    public OLIControllerextensionTEST(ApexPages.StandardController controller) {
        this.opp = (Opportunity)controller.getRecord();

   }
   
   
    public PageReference mySave() {
        update opp.OpportunityLineItems;
        return null;
    }
}

 

 

 

Any help? :)