Play Games

Search This Blog

Friday, January 18, 2019

Sort SFDC records based on multiple fields in SOQL query - Salesforce Globe For You

Problem: We have a requirement where we need to sort lead records based on Company field first and then based on Name.

Solution: Yes, we can sort records based on multiple fields as well.

List<Lead> lstLead = new List<Lead>();
lstLead = [Select id,company,name from Lead where name != null order by Company Asc,name ASC];

system.debug('Sorted Lead Records'+lstLead);