You need to sign in to do that
Don't have an account?
Extension Class/VF Page - Custom Save method not working
This controller extension to the standardsetcontroller defines a custom Save method called 'SaveClose'. A query in the constructor holds the 'InEdit' array of records that should be updated when this method is called. The page loads as expected with the records - but the SaveClose method line for Update 'InEdit' doesn't actually update the records.
I know the method is running - because the page reference lines do run. But the Update InEdit line isn't updating any records. Maybe I'm not defining my array correctly?
Any help or suggestions would be great.
Here is extension class:
public with sharing class InEditExtensionOne {
//Global Variables
private ApexPages.StandardSetController controller;
Private final string InEditUser=UserInfo.getUserId();
public list<case> InEdit { get; set; }
// Standard Controller Constructor
public InEditExtensionOne(ApexPages.StandardSetController Controller) {
this.controller = controller;
this.InEdit=[SELECT Id,CaseNumber,Account.Name,Cancellation_Date__c,Completion_Date__c
FROM Case WHERE InEditUser__c =InEditUser];
}
//Save and Close method
public PageReference SaveClose(){
for(Case e :InEdit){
e.InEditUser__c=Null;
e.InEditTime__c=Null;
e.InEditExpiring__c=Null;
}
Update InEdit;
PageReference pageRef = new PageReference('/500/o');
pageRef.setRedirect(true);
return pageRef;
}
}
Here is the visualforce page:
<apex:page standardController="Case" extensions="InEditExtensionOne" recordSetVar="implementations"> <script LANGUAGE="JavaScript1.2" TYPE="text/javascript"> var allowPrompt = true; function unloadMessage(){ if(allowPrompt){ message = "Wait! Please hit 'Save and Close' before exiting the page." } else { message = "Please confirm your changes." allowPrompt = true; } return message; } function setBunload(on){ window.onbeforeunload = (on) ? unloadMessage : null; } setBunload(true); function NoPrompt() { allowPrompt = false; } </script> <apex:sectionHeader title="New Field Values"/> <apex:form > <apex:pageBlock > <apex:pageMessages /> <apex:pageBlockButtons > <apex:commandButton value="Save and Close" action="{!saveClose}" onclick="NoPrompt();"/> <apex:commandButton value="Save and Next" action="{!saveNext}" onclick="NoPrompt();"/> </apex:pageBlockButtons> <apex:tabPanel switchType="client" selectedTab="TabOne" id="theTabPanel"> <apex:tab label="Standard Details" name="StandardDetails" id="tabOne"> <apex:pageBlockSection title="" showHeader="false" collapsible="false"> <apex:selectList Label="ButtonClick" value="{!onClick}" size="1"> <apex:selectOptions Value="{!Options}"/> </apex:selectList> <apex:inputField Label="Case Owner" value="{!Case.OwnerId}" Required="False"/> <apex:pageBlockSectionItem /> <apex:pageBlockSectionItem /> <apex:pageBlockSectionItem /> <apex:pageBlockSectionItem /> <apex:inputField value="{!Case.Target_SLA_Current__c}"/> <apex:inputField value="{!Case.Implementation_Delay__c}"/> <apex:inputField value="{!Case.Client_Contacted_Date__c}" Required="False"/> <apex:inputField value="{!Case.Delay_Details__c}"/> <apex:inputField value="{!Case.ContactId}" Required="False"/> <apex:pageBlockSectionItem /> <apex:inputTextArea value="{!Case.Implementation_Notes__c}" rows="5" cols="75"/> <apex:inputTextArea value="{!Case.Implementation_Delay_Notes__c}" rows="5" cols="75"/> <apex:pageBlockSectionItem /> </apex:pageBlockSection> </apex:tab> <apex:tab label="Administration" name="Administration" id="tabTwo"> <apex:pageBlockSection title="" showHeader="false" collapsible="false"> <apex:inputField value="{!Case.RC_Setter__c}"/> <apex:inputField value="{!Case.Cancellation_Reason__c}"/> <apex:pageBlockSectionItem /> <apex:pageBlockSectionItem /> <apex:inputField value="{!Case.Completion_Date__c}"/> <apex:inputField value="{!Case.Cancellation_Date__c}"/> <apex:pageBlockSectionItem /> </apex:pageBlockSection> </apex:tab> <apex:tab label="India Operations" name="IndiaOperations" id="tabThree"> <apex:pageBlockSection title="" showHeader="false" collapsible="false"> <apex:inputField value="{!Case.Property__c}"/> <apex:pageBlockSectionItem /> <apex:pageBlockSectionItem /> <apex:pageBlockSectionItem /> <apex:inputTextArea value="{!Case.New_Case_Comment__c}" rows="3" cols="75"/> <apex:pageBlockSectionItem /> <apex:pageBlockSectionItem /> </apex:pageBlockSection> </apex:tab> <apex:tab label="Marketplace Suite" name="Marketplace" id="tabFour"> <apex:pageBlockSection title="" showHeader="false" collapsible="false"> <apex:inputField value="{!Case.Pilot__c}"/> <apex:inputField value="{!Case.Kick_off_Meeting__c}"/> <apex:pageBlockSectionItem /> <apex:inputField value="{!Case.Project_Plan__c}"/> <apex:inputField value="{!Case.Sales_Checklist__c}"/> <apex:inputField value="{!Case.Weekly_Status__c}"/> <apex:pageBlockSectionItem /> <apex:pageBlockSectionItem /> </apex:pageBlockSection> <apex:pageBlockSection title="" showHeader="false" collapsible="false" Columns="1"> <apex:inputTextArea value="{!Case.Historical_Comments__c}" rows="4" cols="185"/> <apex:pageBlockSectionItem /> </apex:pageBlockSection> </apex:tab> <apex:tab label="Migration" name="Migration" id="tabFive"> <apex:pageBlockSection title="" showHeader="false" collapsible="false"> <apex:inputField value="{!Case.Products_Sold__c}"/> <apex:inputField value="{!Case.Account_Set_Up__c}"/> <apex:inputField value="{!Case.Upsell__c}"/> <apex:inputField value="{!Case.Dev_Prep_Work__c}"/> <apex:inputField value="{!Case.Upsell_Detail__c}"/> <apex:pageBlockSectionItem /> <apex:pageBlockSectionItem /> <apex:inputField value="{!Case.Resident_Portal_Last_Activity_Date__c}"/> <apex:inputField value="{!Case.Date_Sent_to_Sales__c}"/> <apex:inputField value="{!Case.Uses_Velocity_06062013__c}"/> <apex:inputField value="{!Case.Date_Back_from_Sales__c}"/> <apex:inputField value="{!Case.WH_Price_List__c}"/> <apex:pageBlockSectionItem /> </apex:pageBlockSection> </apex:tab> </apex:tabPanel> <apex:pageBlockSection title="Selected Implementations" columns="1"> <apex:pageBlockTable value="{!InEdit}" var="c"> <apex:column headerValue="Case No"> <apex:outputLink value="/{!c.id}">{!c.casenumber}</apex:outputLink> </apex:column> <apex:column value="{!c.Account.Name}"/> </apex:pageBlockTable> </apex:pageBlockSection> </apex:pageBlock> </apex:form> </apex:page>
The solution for this was to instantiate a new Case object and have that hold the values of the input fields until I assign values in the save method.
Added to controller extension:
Case theCodex = new Case();
public Case getCodex() {return theCodex;}
public void setCodex(case value) {theCodex = value;}
Added to for loop in save method:
IF(theCodex.OwnerId!=Null){
a.OwnerId=theCodex.OwnerId;
}
In visualforce page - tie input field to the object I create, instead on the standard controller:
All Answers
Note - the for loop of fields do update.
Its just the other fields on the VF layout that are not updating.
It might seem a little redundant, but try adding/modifying to the below lines in red. If the issue is what I think it is, the below should fix it.
public with sharing class InEditExtensionOne {
//Global Variables
private ApexPages.StandardSetController controller;
Private final string InEditUser=UserInfo.getUserId();
public list<case> InEdit { get; set; }
public list<Id> caseIds;
// Standard Controller Constructor
public InEditExtensionOne(ApexPages.StandardSetController Controller) {
this.controller = controller;
this.InEdit=[SELECT Id,CaseNumber,Account.Name,Cancellation_Date__c,Completion_Date__c
FROM Case WHERE InEditUser__c =InEditUser];
for(Case c: InEdit)
caseIds.add(c.Id);
}
//Save and Close method
public PageReference SaveClose(){
List <Case> casesToUpdate = [Select Id, InEditUser__c, InEditTime__c, InEditExpiring__c, from Case where Id in :caseIds];
for(Case e :casesToUpdate){
e.InEditUser__c=Null;
e.InEditTime__c=Null;
e.InEditExpiring__c=Null;
}
Update casesToUpdate;
PageReference pageRef = new PageReference('/500/o');
pageRef.setRedirect(true);
return pageRef;
}
}
The solution for this was to instantiate a new Case object and have that hold the values of the input fields until I assign values in the save method.
Added to controller extension:
Case theCodex = new Case();
public Case getCodex() {return theCodex;}
public void setCodex(case value) {theCodex = value;}
Added to for loop in save method:
IF(theCodex.OwnerId!=Null){
a.OwnerId=theCodex.OwnerId;
}
In visualforce page - tie input field to the object I create, instead on the standard controller: