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
SahilSFSahilSF 

DB query for selective records.

Hi All,

 

Is it possible to get the top 3 records from a custom object using a query for e.g. i have 5 records for todays date (14 Mar) and 4 records for tomorrow (15 Mar) and so on. What I need here is to get the top 3 records for each day.

 

Thanks

ShrutiShruti

try using 'order by createddate desc'  to get the top most records

Imran MohammedImran Mohammed

As Shruti said, fetch the records using order by created date desc and iterate over the list to find the top 3 records for each day.

MiddhaMiddha

example of what Imran is saying:

 

Select Id, Name from Custom_Object__c Order By CreatedDate Desc limit 3

 

This should work.