0
List<Account> Acc// this list contains Account records.
Acc.Sort() is not working

How to sort the records based on Created Date? Basically i need the recently record from the Acc list

1
  • Hi, and welcome to SFSE! I linked a couple of answers that include enough code to get you started with your requirement and an explanation of how they work. Hopefully these answers can get you to your objective. If these answers don't work, you can edit your question to include more details and let us know, and we'll be happy to reopen your question for you.
    – sfdcfox
    Mar 25, 2021 at 12:23

1 Answer 1

1
List<Account> Acc = [SELECT Id,Name from Account Order by CreatedDate DESC]

You dont need to use sort function separately.

1
  • i can't use SOQL query because i have to sort that list inside for loop
    – Ram
    Mar 25, 2021 at 9:46

Not the answer you're looking for? Browse other questions tagged or ask your own question.