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
vishnu vardhan 142vishnu vardhan 142 

Query to fetch recently created 10 records from object

Hi All,

How to write soql Query to get recently created 10 records from an Object
Maharajan CMaharajan C
Please refer the below query:

Select Id,Name,CreatedDate  from Account order by CreatedDate desc Limit 10

Instead of Account ==> use your Name.

In Select Query add your required fields( ie, id,name, Created Date)

Thanks,
Maharajan.C
Ankit RathorAnkit Rathor
Hi Vishnu ,

Please try this code:
List <Account> accounts = new List<Account>();
accounts [Select Id from Account Order by CreatedDate DESC LIMIT 10];
 
Please let me know if you have any other query. If this solution is helpful then please mark it as Best Answer.

Thanks,
Ankit Rathor 
Ajay K DubediAjay K Dubedi
Hi Vishnu,

I hope you are doing well, You can use this code for Account object.
If you want this for any other object in salesforce then you can change Object name.

Try this ->
list<account> accList = [select id from account order by createdDate DESC limit 10];

I hope you find the above solution helpful. If it does, please mark as Best Answer to help others too.

Thanks,
Ajay Dubedi
Deepali KulshresthaDeepali Kulshrestha
Hi vishnu ,

You can try below snippet of code, it is working according to your requirement.
List <Account> accountList = [select Id, Name  from Account order by createdDate DESC limit 10];

I hope you find the above solution helpful. If it does, please mark as Best Answer to help others too.

Thanks and Regards,
Deepali Kulshrestha.