0

I have a set of select options in a dropdown which the user selects and based on the option selected different sets of pageblocktables are rendered. I want them to be able to inline edit and save each of these tables. When I give these tables inline edit/save functionality without using the select list, it works perfectly. However, when I use inline editing with selectlist; after click on the save button, the page reloads but then does not show any tables and data does not get saved. I am guessing there is problem with the doSave() function in my code.

VF code:

<apex:page controller="OppsController">
<apex:form >
   <apex:panelGrid columns="2">
        <apex:selectList value="{!SectionNames}" required="True" size="1" multiselect="false">
            <apex:selectOptions value="{!SectionItems}" />
            <apex:actionSupport event="onchange" action="{!updateData}"/>   
        </apex:selectList> 

   </apex:panelGrid> 


 <apex:outputPanel >
 <apex:outputPanel id="section1" rendered="{!section1}" >
  <apex:pageBlock >
<apex:commandButton value="Save" action="{!doSaveUS}" />
      <apex:pageBlockTable value="{!OppContentUS}"  var="item" style="text-align:left;" >
             <apex:inlineEditSupport showOnEdit="SaveActiveState"  /> 

                    <apex:facet name="header">US New Business This Quarter</apex:facet>

                    <apex:column >
                            <apex:facet name="header">Owner.Name</apex:facet>
                           {!item['Owner.Name']}
                    </apex:column>
                    <apex:column >
                            <apex:facet name="header">Account Name</apex:facet>
                            {!item['Account.Name']}
                    </apex:column> 
                     <apex:column >
                            <apex:facet name="header">Opportunity Name</apex:facet>
                            {!item['Name']}
                    </apex:column>                     
                    <apex:column >
                            <apex:facet name="header">Stage</apex:facet>
                           {!item['StageName']}          
                    </apex:column>
                    <apex:column >
                            <apex:facet name="header">Total Contract Value</apex:facet>
                            {!item['Total_Contract_Value__c']}  
                    </apex:column>  
                    <apex:column >
                            <apex:facet name="header">Tier</apex:facet>
                             {!item['Opp_Tier_Group__c']}  
                    </apex:column> 
                    <apex:column >
                            <apex:facet name="header">Notes</apex:facet>
                             {!item['Opp_Owner_Notes__c']}  
                    </apex:column>                      
</apex:pageBlockTable>


</apex:pageBlock>  
</apex:outputPanel>
</apex:outputPanel>   


 <apex:outputPanel >
 <apex:outputPanel id="section2" rendered="{!section2}" >
 <apex:pageBlock >
  <apex:commandButton value="Save" action="{!doSaveUK}" />
      <apex:pageBlockTable value="{!OppContentUK}"  var="item" style="text-align:left;" >
             <apex:inlineEditSupport showOnEdit="SaveActiveState"  /> 

                    <apex:facet name="header">UK New Business This Quarter</apex:facet>

                    <apex:column >
                            <apex:facet name="header">Owner.Name</apex:facet>
                           {!item['Owner.Name']}
                    </apex:column>
                    <apex:column >
                            <apex:facet name="header">Account Name</apex:facet>
                            {!item['Account.Name']}
                    </apex:column> 
                     <apex:column >
                            <apex:facet name="header">Opportunity Name</apex:facet>
                            {!item['Name']}
                    </apex:column>                     
                    <apex:column >
                            <apex:facet name="header">Stage Name</apex:facet>

                               <apex:outputfield value="{!item.StageName}" ></apex:outputField>     
                    </apex:column>   
                    <apex:column >
                            <apex:facet name="header">Total Contract Value</apex:facet>
                            {!item['Total_Contract_Value__c']}  
                    </apex:column>  
                    <apex:column >
                            <apex:facet name="header">Tier</apex:facet>
                             {!item['Opp_Tier_Group__c']}  
                    </apex:column> 
                    <apex:column >
                            <apex:facet name="header">Notes</apex:facet>
                             {!item['Opp_Owner_Notes__c']}  
                    </apex:column>                      
</apex:pageBlockTable>                 
</apex:pageBlock>  
</apex:outputPanel>
</apex:outputPanel>  

Controller:

public with Sharing class OppsController {

      public String SectionNames {get;set;}
      public Boolean section1 {get; set;}
      public Boolean section2 {get; set;}


      public List<SelectOption> getSectionItems(){
        section1 = false;
        section2 = false;

         List<SelectOption> SectionNames = new List<SelectOption>();
         SectionNames.add(new SelectOption('','-- Select --'));
         SectionNames.add(new SelectOption('USA New Business','USA New Business'));
         SectionNames.add(new SelectOption('UK New Business','UK New Business'));
         return SectionNames;

     }


       public Pagereference updateData() {
         if(SectionNames == 'USA New Business') {
              section1 = true;                     
         } 

         else if(SectionNames == 'UK New Business') {

              section2 = true;  
         }

        return null;
     }

List<Opportunity> oppsUK = new List<Opportunity>(); 
List<Opportunity> oppsUS = new List<Opportunity>(); 

public OppsController()  {
     oppsUK =  [SELECT ID, Account.ID, Account.Name, Name, Owner.Name, CloseDate, StageName, Opp_Tier_Group__c, Opp_Owner_Notes__c, Total_Contract_Value__c    
               FROM Opportunity
               WHERE CloseDate = THIS_QUARTER and  Sales_Team__c = 'EMEA' AND Type = 'New Business' 
                ]; 

oppsUS =  [SELECT ID, Account.ID, Account.Name, Name, Owner.Name, CloseDate, StageName, Opp_Tier_Group__c, Opp_Owner_Notes__c, Total_Contract_Value__c    
               FROM Opportunity
               WHERE CloseDate = THIS_QUARTER and  Sales_Team__c = 'US' AND Type = 'New Business' 
                ]; 
      }   

   public List<Opportunity> getOppContentUK() {                                      
        return this.oppsUK;
    }




    public PageReference doSaveUK() {
        system.debug(oppsUK);
        update oppsUK;
        return ApexPages.CurrentPage();

    }



   public List<Opportunity> getOppContentUS() {                                      
        return this.oppsUS;
    }




    public PageReference doSaveUS() {
        system.debug(oppsUS);
        update oppsUS;
        return ApexPages.CurrentPage();

    }
}
  • How do you format this damn thing??!! Its cutting off half the code – Mike Dec 18 '15 at 20:48
  • 1
    Edit our post, select the Visualforce or Apex and click the {} button to format. – Keith C Dec 18 '15 at 20:51
  • @KeithC Any idea about the posted question? – Mike Dec 19 '15 at 0:25
  • 1
    You're probably getting a DmlException. Wrap your update call in a try/catch. In your catch block make sure you call ApexPages.addMessages then return null. – Adrian Larson Dec 19 '15 at 4:28
1

Issue with

 public List<SelectOption> getSectionItems(){
        section1 = false;
        section2 = false;

         List<SelectOption> SectionNames = new List<SelectOption>();
         SectionNames.add(new SelectOption('','-- Select --'));
         SectionNames.add(new SelectOption('USA New Business','USA New Business'));
         SectionNames.add(new SelectOption('UK New Business','UK New Business'));
         return SectionNames;

     }

Remove

section1 = false;
section2 = false;

this and add into constructor

what happend constructor always call once when page load but this getSectionItems method call everytime whenever we call a method from page

  • I added this in. Same issue. Not saving. Page reloads and the tables disappear. – Mike Dec 19 '15 at 7:27
  • are you able to get picklist values i controller? – Ratan Paul Dec 19 '15 at 7:31
  • Not sure what you mean by that. The table values after edit are not getting saved. The selectlist seems to be blocking the update. – Mike Dec 19 '15 at 7:35
  • @Mike I just used your code in my org it is working fine – Ratan Paul Dec 19 '15 at 7:45
  • I am indeed using it. I have used apex:inlineEditSupport in my table and I use apex:outfield on the ones I want to inline edit. It works perfectly without apex:selectList but with that inlineEditing doesn't work. – Mike Dec 19 '15 at 7:48

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.