0

I have a standardsetcontroller to display some records. I'm adding a row level button to remove the records from the list using a rowIndex variable. I'm getting the collection object in a list and am trying to remove the object.

Here is the function:

    //Deletes row
public void deleteRow(){
    List<cust_obj__c> objs = setCon.getRecords();
    cust_obj__c removedObj = objs.get(rowIndex);
    if(delObjs == null) {
        delObjs = new List<cust_obj__c>();
    }

    if (removedObj.id != NULL) {
        delObjs.add(removedObj);
    }
    objs.remove(rowIndex);
}

However when I try to do this, it gives an error System.FinalException: Collection is read-only.

I understand that I'm trying to delete a read only collection and would possibly have to clone the records and remove it from the list. But I do not see any methods on StandardSetController which do an update on the records. So even if I do something like this:

    cloned_objs = setCon.getRecords().deepClone(true, true, true);

How do I refresh my list on the VF page and how do I save the cloned objs back. Am I missing something here?

  • You can remove records from the selected collection by calling setSelected with a new list. There's no method to setRecords, though. – Adrian Larson Jan 14 '17 at 0:28
  • Thanks. I see. I wasn't sure what setselected does. The documentation doesn't say much. Would you be able to throw some light on how it works in case of pagination? Does it only set the records in the current page view? – gerad26 Jan 14 '17 at 0:39
  • What are you even trying to accomplish? Please outline it at a high level. – Adrian Larson Jan 14 '17 at 0:40
  • I'm using a standard set controller to display some records . I have a delete button next to each object in the VF page which grabs the rowIndex and am trying to remove the record from the list returned by setCon.getRecords – gerad26 Jan 14 '17 at 0:47
  • 3

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.