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();
}
}
DmlException
. Wrap yourupdate
call in atry
/catch
. In yourcatch
block make sure you callApexPages.addMessages
thenreturn null
.