2

I have a Paginated List displayed on the visual force page and in the backend I was using a StandardSetController to control the pagination. However, one column on the table is an aggregated field whose calculation is done in a wrapper class. Recently, I want to sort the paginated list against the calculated field. And unfortunately the calculated result cannot be done on the data model(SObject) level.

So I am thinking to passed a sorted list of SObject to the StandardSetController constructor. That is to sort the record before it has been pass into the StandardSetController. The code is like below:

        List<Job__c> jobs = new List<Job__c>();
        List<Job__c> tempJobs = Database.Query(basicQuery + filterExpression);
        //sort with values
        List<JobWrapper> jws = createJobWrappers(tempJobs);
        JobWrapper.sortBy = JobWrapper.SORTBY_CALCULATEDFIELD_ASC;
        jws.sort();
        for(JobWrapper jw : jws){
            jobs.add(jw.JobRecord);
        }
        jobs = jobs.deepClone(true, true, true);

        StandardSetController con = new ApexPages.StandardSetController(jobs);
        con.setPageSize(10);

However after executing the last line system throw exception:Modified rows exist in the records collection!

I did not modify any rows in the controller. Could anyone help me understanding the exception?

5
  • If you're using the wrapper on the page, you might have to clone that one as well, see this post: salesforce.stackexchange.com/questions/10027/… Commented Mar 7, 2014 at 8:42
  • I was not use that 'jws' wrapper on the page. I created another list of wrappers to bind to the page.(not very efficiently)
    – bluecat
    Commented Mar 7, 2014 at 18:26
  • Is it an option to calculate the aggregated field in advance, i.e. in the record trigger? Then you could do the sort in the query.. Alternatively, doing con.save() before con.setPageSize(10) might help (although very inefficient). Lastly, I know there is a known issue resulting in this error, but it doesn't seem to be this issue.. Commented Mar 7, 2014 at 20:21
  • yeah.That probably the most efficient way to do the sorting. It's just the calculation is complex I need to add multiple fields to achieve the goal....
    – bluecat
    Commented Mar 7, 2014 at 21:43
  • Am also looking for same kind of solution..Were you able to solve.. Thanks <br/> Chitra Commented Jun 25, 2014 at 7:57

0

You must log in to answer this question.

Browse other questions tagged .