+ Start a Discussion
kodeXkodeX 

Retrieve comments

After executing the following SOQL query-

 

SELECT FEEDPOST.BODY,FEEDPOST.FEEDITEMID,FEEDPOST.PARENTID,"+
                "(SELECT Id, CommentBody FROM FEEDCOMMENTS) FROM" +
                " NEWSFEED WHERE TYPE = 'USERSTATUS' ORDER BY CreatedDate  DESC, ID DESC");

 

In Soap, How to get the CommentBody while iterating in the loop?

 

1. s.getChild("FeedComment").getField("CommentBody") OR

2. s.getChild("CommentBody").getValue();

 

Note that Above 2 statements dont yield successful results!

 

What is the solution?

Best Answer chosen by Admin (Salesforce Developers) 
Devendra@SFDCDevendra@SFDC
Hi,
Try this:

queryResults = connection.query
("SELECT Id,FeedPost.Body,FeedPost.FeedItemId, (SELECT Id,CommentBody FROM FeedComments) FROM NewsFeed WHERE ParentId='XXXXXXXXXXXXX');

 

Please check for retriving comments for particular NewsFeed.

 

Thanks,

Devendra

All Answers

Devendra@SFDCDevendra@SFDC

 

Hi kodeX,

 

Try this:

 

NewsFeed nf = [SELECT Id, Body, (Select Id, CommentBody FROM FeedComments) FROM NewsFeed WHERE ParentId = 'XXXXXXXXXXXX'];

System.debug(nf.Id);
System.debug(nf.Body);
for (FeedComment fc : nf.FeedComments) {
   System.debug(fc.Id);
   System.debug(fc.CommentBody);
}

 

Hope this helps.

 

Thanks,

Devendra

kodeXkodeX

There is no method debug in "System" class.

Executing the SOQL query returns QueryResults object, which is incompatible with NewsFeed object.

 

Dev,Please provide appropriate working solution!

Devendra@SFDCDevendra@SFDC

 

Hi kodeX,

 

From your org, Please take Id of FeedItem which has few comments on it.

 

Hard Code the id in above query and execute the code in your Sytem Log.

 

I will check for the SOAP API.

 

Thanks,

Devendra

 

kodeXkodeX

I hard coded feeditemid as you said,

but it is returning all the comments on all posts, not of a specific post!

How can i get comments for a specific post?

 

 

Devendra@SFDCDevendra@SFDC

 

Hi kodeX,

 

Can you please your code here?

 

Thanks,

Devendra

kodeXkodeX

I have specified FeedItemId.

Here it is-

 

queryResults = connection.query 
     	("SELECT Id,FeedPost.Body,FeedPost.FeedItemId, (SELECT Id,CommentBody FROM FeedComments WHERE FeedItemId='0D590000006TWurCAG') FROM NewsFeed WHERE Type= 'UserStatus' ORDER BY ID DESC LIMIT 20");

for(SObject ob : queryResults.getRecords())  
{ System.out.println(ob.getChild("FeedComment").getChild("Records").getField("CommentBody").toString());
}

 

Devendra@SFDCDevendra@SFDC
Hi,
Try this:

queryResults = connection.query
("SELECT Id,FeedPost.Body,FeedPost.FeedItemId, (SELECT Id,CommentBody FROM FeedComments) FROM NewsFeed WHERE ParentId='XXXXXXXXXXXXX');

 

Please check for retriving comments for particular NewsFeed.

 

Thanks,

Devendra

This was selected as the best answer
kodeXkodeX

Hey thanks its Working for retreiving comments for particular user in your whole newsfeed!

 

To get comments for each post the soql query is-

SELECT CreatedById,CreatedBy.FirstName,CreatedBy.LastName,FeedPost.FeedItemId,FeedPost.Body,FeedPost.Type,(SELECT CreatedBy.FirstName,CreatedBy.LastName,CommentBody from FeedComments FROM NewsFeed WHERE Type='UserStatus' OR Type='TextPost' ORDER BY CreatedDate DESC LIMIT 20