Can any one help me out on this?
I have a created a vf page ,i have been using the standard button functionality SAVE and CANCEL .But the problem is the Save button does not work as per the requirement.when i select few cases for Mass Closer of cases ,i give the data as "Status=closed" click on save it should save the data ,but what happens here is Instead of closing the selected cases,it Closes all the records which are not selected .
For Example : I have few cases number as 471771 ,72 ,73 ,74 ,75 .Now i will select 71 ,72,73 cases for Mass closing and once i select the Mass close button and give the case status as "closed" and update the comments.click on the save button.The save button functionality should save the selected cases and update it.What happens is the selected cases as well as the non selected cases get closed.
VF Page :
<apex:page controller="MassCloseCasesController" sidebar="false">
<apex:form >
<apex:SectionHeader title="Close Cases"/>
<apex:pageBlock >
<apex:pageBlockButtons location="Both">
<apex:commandButton action="{!Save}" value="Save"/>
<apex:commandButton action="{!Cancel}" value="Cancel" immediate="true"/>
</apex:pageBlockButtons>
<apex:pageBlockSection collapsible="false" title="Case Information" >
<apex:inputField value="{!objCase.Status}"/>
<apex:inputField value="{!objCase.Reason_For_Resolution__c}" label="Reason For Resolution"/>
<apex:inputField value="{!objCase.Comment__c}" label="Internal Comments"/>
<apex:inputField value="{!objCase.Do_Not_Send_Email_Case_Closure__c}" label="Do Not Send Email Case Closure"/>
</apex:pageBlockSection>
</apex:pageBlock>
</apex:form>
</apex:page>
Code :
public with sharing class MassCloseCasesController {
public Case objCase {get;set;}
private List<Case> lstCase;
public MassCloseCasesController()
{
objCase = new Case();
lstCase = new List<Case>();
lstCase = [SELECT Id, Status, Reason_For_Resolution__c, Comment__c, Do_Not_Send_Email_Case_Closure__c FROM Case];
}
public PageReference save()
{
for(Case objCaseRecord: lstCase)
{
objCaseRecord.Status = objCase.Status;
objCaseRecord.Reason_For_Resolution__c = objCase.Reason_For_Resolution__c;
objCaseRecord.Comment__c = objCase.Comment__c;
objCaseRecord.Do_Not_Send_Email_Case_Closure__c = objCase.Do_Not_Send_Email_Case_Closure__c;
}
update lstCase;
return new pagereference('/500');
}
public PageReference cancel()
{
return new pagereference('/500');
}
}