0

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'); 
                          } 
}

enter image description here Any help very much appreciated.

4
  • is mass close is a custom button here?
    – Ratan Paul
    Commented Nov 17, 2015 at 7:33
  • @RatanPaul:Mass Close is a custom button created.
    – nikkey
    Commented Nov 17, 2015 at 7:54
  • yeah then use below @himanshu code. This will work.
    – Ratan Paul
    Commented Nov 17, 2015 at 8:07
  • @RatanPaul:I tried the below code...its not working...When i go for Mass closer case --select the cases and give the status as closed and click on save button.The selected cases is not getting closed with the below code and returns to the same page were all the records selected and unselected cases.
    – nikkey
    Commented Nov 17, 2015 at 8:15

2 Answers 2

0

That is because you have following query in your constructor

lstCase = [SELECT Id, Status, Reason_For_Resolution__c,
 Comment__c, Do_Not_Send_Email_Case_Closure__c FROM Case];

which select all the cases regardless what you select from list view.

You need to pass the selected items only in your constructor.

your code should be updated in following ways

Visualforce page

<apex:page standardcontroller="case" extensions="MassCloseCasesController" sidebar="false" recordSetVar="cases"> 
  <apex:form > 
    <apex:SectionHeader title="Close Cases"/> 
      <apex:pageBlock > 
        <apex:pageBlockButtons location="Both"> 
          <apex:commandButton action="{!caseSave}" 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>

Apex Class:

public with sharing class MassCloseCasesController { 

      public Case objCase {get;set;} 
      private List<Case> lstCase{get;set;} 
      public MassCloseCasesController(ApexPages.StandardSetController standardController) 
                            { 
                               objCase = new Case(); 
                               lstCase = new List<Case>(); 
                               lstCase = (List<Case>) standardController.getSelected();


     } 
     public PageReference casesave() 
                           { 
                              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'); 
                          } 
}
6
  • :Thanks for your reply.When i go for Mass closer case --select the cases and give the status as closed and click on save.The selected cases is not getting closed with the above code and returns to the same page with the records selected and unselected cases.
    – nikkey
    Commented Nov 17, 2015 at 8:11
  • there is basic problem of your case and I don't know what is your business process. You select mulitple cases from list view but you are binding a single case to the front end. do you want to apply same on rest of the selected cases?
    – Himanshu
    Commented Nov 17, 2015 at 8:24
  • :The main idea is ...As per standard functionality of "Close " button ,which is used for mass closer of cases.we would like to have the same functionality with Custom button.we have created the vf page because we would like to have the field added and replacement of the fields to be done.In standard functionality of page layout for "close case layout " we don't have an option for additional of fields or replacement fields to be done for mass closer of cases.
    – nikkey
    Commented Nov 17, 2015 at 8:35
  • :The selected cases are not getting closed and the status is not getting updated as closed.Any help very much appreciated.
    – nikkey
    Commented Nov 17, 2015 at 8:45
  • please check updated code. I tested it and it is working. change which i made are private List<Case> lstCase{get;set;}
    – Himanshu
    Commented Nov 17, 2015 at 8:53
0

Here is something you can do:

Change your Close(list view button) to execute OnClick Javascript and write this code asthe javascript.

var ids= {!GETRECORDIDS($ObjectType.Case)}; 
if(ids.length < 1 ) 
 alert('Please select at least one case.'); 
else 
 window.open('/apex/YourPageName?ids='+ids.join(',')); //Replace YourPageName with your VF page name

Then in your VF page controller, change the code to this.

public with sharing class MassCloseCasesController { 

      public Case objCase {get;set;} 
      private List<Case> lstCase; 
      public List<string> caseIDS(get;set;}
      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]; 
String ids = ApexPages.currentPage().getParameters().get('ids');
if(ids != null)
{
 caseIDS = ids.split(',');
 lstCase = [SELECT Id, Status, Reason_For_Resolution__c, Comment__c, Do_Not_Send_Email_Case_Closure__c FROM Case where Id IN :caseIDS]; 
}
                            } 
     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'); 
                          } 
}
6
  • And PLEASE PLEASE PLEASE don't blindly copy the code. I haven't tested it. Please change the code as per your configurations. Commented Nov 17, 2015 at 8:58
  • :Thanks for your reply.When i select the Mass cases and click on Mass button , i get an Error as :java.lang.IllegalArgumentException: id 5004B000000qtBl,5004B000000qtBm must be 15 characters
    – nikkey
    Commented Nov 17, 2015 at 10:00
  • if you are using this solutions you need to split the ids in your controller by comma
    – Himanshu
    Commented Nov 17, 2015 at 10:49
  • @Himanshu:i tried using both the codes,it throws the same error.At which part of the code the ids needed to separated by the comma.
    – nikkey
    Commented Nov 17, 2015 at 11:27
  • Himanshu is right, you have to split the id list in controller. caseIDS = ids.split(','); This line is the separator. I removed one extra parameter from the split function. Try now. Commented Nov 17, 2015 at 11:44

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .