function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
shachnashachna 

Can I Sort Records before rendering as a PDF?

We currently have an old VF page that runs a series 'render' loops to sort reocrds for a PDF. Is there a way to set up the VF page (or possibly use a controller) to sort the records the way I want before running the renderAs='PDF' command so that I'll only need a single loop?

Bhawani SharmaBhawani Sharma
You can do this if any controller is associated with this. You can use comparable interface to define your own sorting criteria.
shachnashachna

There is an associated controller that looks like this:
public with sharing class DispAllRecs
{

public DispAllRecs(ApexPages.StandardSetController controller)
{
controller.setPageSize(1000);
}
public static testmethod void testm1()
{
test.startTest();
list cg=[select id from Clinical_Goals__c
limit 2000];
ApexPages.StandardSetController con=new
ApexPages.StandardSetController(cg);
DispAllRecs objDAR= new DispAllRecs(con);
test.stopTest();
}
}

Can you please send a sample (or link to a sample) of the code I would need to use?

Bhawani SharmaBhawani Sharma
You can use order by clause in your query.
[select id from Clinical_Goals__c order by Name ASC/DESC limit 2000];
shachnashachna
Thanks
Bhawani SharmaBhawani Sharma
Did it help?