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
spaspa 

SOQL to get list of new comments

How do I get a list of new Comments added since a certain time?  

I can get new feedposts/newsfeed by using the CreatedDate as a filter, but SOQL of the form

 

SELECT ID from FeedComment WHERE CreatedDate >= TODAY 

 

does not work as feedComments cannot be queried on their own and using it like so

 

SELECT ID, (SELECT ID FROM FeedComments WHERE CreatedDate >= TODAY) from NewsFeed 

 

returns all newsfeeds not only the ones which have Feedcomments. 

 

thanks,

sp

cloudcodercloudcoder

You can not query FeedComments directly, you will need to go through the *Feed entities; in your case this would be NewsFeed.

 

Try something like:

 

SELECT Id

   (SELECT id, CommentBody, CreatedDate,

    CreatedById, CreatedBy.FirstName, CreatedBy.LastName

    FROM FeedComments 

WHERE CreatedDate = TODAY

ORDER BY CreatedDate, ID DESC)

FROM NewsFeed

 

Remember however that this will return ALL NewsFeed Items, not just those with FeedComments from today. You will need to loop through the results and retrieve what you need by checking whether NewsFeed.FeedComments.size() > 0

 

Just be careful of doing an open ended query on *Feed entities as you can easily return a LOT of records. 

 

spaspa

That is what I was trying to avoid. Any other solutions out there?

cloudcodercloudcoder

I tried a few things and not much luck. Can you explain your use case a little and perhaps we can brainstorm a solution.

spaspa

I want to be able to show all new posts & updates on everything that a user is following. I can easily get all new posts but not the comments without having to troll through all posts.