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
Vinicius Vandre 5Vinicius Vandre 5 

Help retrieving list of most recent records for each value in a set.

Hello! I'm having trouble figuring this one out. So any help will be highly appreciated!

I have a custom picklist field in Order.

I wish to retrieve all the most recent records for each value in the picklist.

Let's say that there are 10 Order records and that the picklist has values A,B,C. What I would like to retrieve (in a single query to avoid SOQL limits) is a list of the 3 most recent records that have each value.

How would you achieve this?

 

Dosbol TDosbol T
Hi there, please try this one:
 
SELECT Id, Name, Picklist_Field__c
FROM Order
WHERE Picklist_Field__c IN ('A', 'B', 'C')
ORDER BY CreatedDate DESC
LIMIT 3