Skip to content

Class to order a list of sObject records based on a field and direction.

Notifications You must be signed in to change notification settings

saicharanreddyk/sObjectListSort

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

17 Commits
 
 
 
 

Repository files navigation

sObjectListSort

This utility class provides a way to custom sort of a list of sObject records by specifying the field name and the sort direction. Useful in circumstances where you can't create the order you want using a SOQL query or don't want to re-query records each time a sort is required.

Usage

// Sort a list of Opportunities by Amount descending
List<Opportunity> opps = [Select Id, Name, StageName, Amount, CloseDate From Opportunity];
opps = SObjectListSort.sortRecords(opps, 'Amount', 'desc');

// Sort by Name
opps = SObjectListSort.sortRecords(opps, 'Name', 'asc');

// Sort by close date
opps = SObjectListSort.sortRecords(opps, 'CloseDate', 'asc');

There are other code examples in the test class.

About

Class to order a list of sObject records based on a field and direction.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • Apex 100.0%