I am trying to use the StandardSetController to update set of records. the code below was using StandardController to update just a single record. I want to use List for the Case object to iterate through and save. How can modify this code to do so ?

public with sharing class ListEditor {

    ApexPages.StandardSetController controller;
    public string ref_suffix {get;set;}
    public Case a;
    public string ref_id {get;set;}
    public string status {get;set;}
    public string name{get;set;}
    public string ref {get;set;}

    public ListEditor(ApexPages.StandardSetController ctrl) {    
       controller= ctrl;
       ref = ApexPages.currentPage().getParameters().get(label.RecordType);
       ref_suffix = ref.subStringAfter(label.UNDERSCORE);
        ref_id = Utils.getRecordTypes().get(ref);
        a = ((Case)ctrl.getRecord());
        a.RecordTypeId = ref_id;
            a= [select nameCase,statusCase from Case where id =: a.id Limit 1];
            name = a.nameCase;
            status= a.statusCase;

        } else{


    Public PageReference save() {
        boolean error = false; 
        a.nameCase = name;

        try {
            // some logic        
        else a.name = null;
        } catch(Exception e) {
            //some ecxeption

    Public PageReference cancel() {
        return controller.cancel();

1 Answer 1


I wont completely rewrite the class for you but you can be very close to having this work with a standardSetController by doing the following

Add a controller property for a soql string

private string c_soql            {get;set;}

Set that property in your class constructor. Just create a soql query in string form

soql = 'Select nameCase, statusCase From Case Where '; // you need to add your criteria here

Create another controller property that is your standardsetcontroller

public ApexPages.StandardSetController ssc {
     get {
          if(ssc == null){
               ssc = new ApexPages.StandardSetController(Database.getQueryLocator(soql));
          return ssc;

Add a method to the class to return the list of cases for the VF page

  public List<Case> getMyCases() {
        return (List<Case>)ssc.getRecords();

You must log in to answer this question.

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