0

Lets take the example of the standard objects CollaborationGroup(CG) and CollaborationGroupFeed(CGF). A single CG record can have multiple related CGF records. If I have 10 CG records I want to get only 1 related CGF record for each CG record sorted by CreatedDate (descending) so that finally I will have only 10 CGF records.

So, for example, if there are 3 CGF records CGF1, CGF2 & CGF3 (written in descending order (by createddate)) for a single CG record CG1. I only want to get CGF1 as the result of my SOQL query.

1 Answer 1

0

I am not aware of object Collaboration Group hence taking example of other standard relationship to query only 1 record.

Here in my example I have taken account, contact where Account can have multiple contacts associated but we will only query 1 using below query

SELECT Id,(SELECT Id,Name,CreatedDate FROM CONTACTS order by createdDate DESC LIMIT 1 ) FROM Account 

Inner query will only output one contact for each account.

1
  • Thanks for the answer man! This worked with the CG & CGF objects as well. The modified query is - SELECT Id, Name, (SELECT Id, CreatedDate FROM Feeds order by CreatedDate DESC LIMIT 1 ) FROM CollaborationGroup Commented May 27, 2022 at 13:16

You must log in to answer this question.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.