Yes, you can use the query you mentioned, but with a small change. Instead of Contact in the subquery, give the plural form - Contacts.
Select id, Name, (Select id,name,CreatedDate from Contacts ORDER BY CreatedDate LIMIT 5) from Account
Regards, Satish Kumar Please mark my answer as a solution if it was helpful so it is available to others as a proper solution. If you felt I went above and beyond, please give me Kudos by clicking on the star icon.
Thanks for your reply. Yes you are correct that is Contacts. But In reusult LIMIT key word and Order By clause is not working. It is showing more contacts reocords not 5. but I mentioned limit 5 only.
Instead of Contact in the subquery, give the plural form - Contacts.
Select id, Name, (Select id,name,CreatedDate from Contacts ORDER BY CreatedDate LIMIT 5) from Account
Regards,
Satish Kumar
Please mark my answer as a solution if it was helpful so it is available to others as a proper solution.
If you felt I went above and beyond, please give me Kudos by clicking on the star icon.
Hi Satish,
Thanks for your reply. Yes you are correct that is Contacts. But In reusult LIMIT key word and Order By clause is not working. It is showing more contacts reocords not 5. but I mentioned limit 5 only.
Regards
Venkat
HI ALL
Set<Id> accIds = new Set<Id>();
List<Account> accList = [select id from Account];
for(Account accRec : accList){
accIds.add(accRec.Id);
}
List<Contact> conList = [select id,name,CreatedDate from Contact Where AccountId In : accIds order by CreatedDate DESC Limit 5];
System.debug('======conList======'+conList+'===='+conList.Size());
Like this I am getting Correct Result.
Plese reply If it is correct process. Other give some simple query.
Regards
Venkat