2

Hey guys I've been experimenting with different queries to try and get all Chatter Posts and their comments within the last 24hr period, but realize that doing this without Apex Triggers is much more difficult with pure SOQL than not.

I've tried using Multi-level Relationships on Chatter Comments example but this doesn't seem to work for me as I am not using objects. I'm hoping someone could give me a hand with creating the correct SOAP soql call to get Chatter Posts (and replies) that have been created or commented on in the last 24 hours.

Thanks guys!

1 Answer 1

1

This will Select correctly based on the question above, hope this helps someone else. Cheers.

SELECT 
        Id, 
        LastModifiedDate,
  (
    SELECT 
            Id, 
            CreatedDate

    FROM FeedComments 

    ORDER BY CreatedDate ASC
  )

FROM UserFeed

WHERE (
            (
              ParentId = {$this->uid}
            )

        AND (
              LastModifiedDate > {$this->lastModStamp}
            )
      )

OR    (
            (
              CommentCount > 0 
            )

        AND (
              CreatedDate > {$this->lastModStamp} 
            )
      )

ORDER BY CreatedDate DESC;

A good way to test this is to flip the

OR ((CreatedDate > YESTERDAY) AND (CommentCount > 0))

to

OR ((CreatedDate < YESTERDAY) AND (CommentCount > 0))

and use something like this to run through it

        header('Content-Type: text/plain');

        $query      = str_replace('{/id}', "'".SF_UID."'", $_POST['q']);
        $response   = $mySforceConnection->query($query);
        $sResult    = New QueryResult($response);

        $i=0;
        foreach ($sResult as $splObject)
        {
            echo "ID: {$sResult->records[$i++]->Id[0]}\n";
            print_r($splObject->fields);
            echo "\n\n";

            if (is_array($splObject->queryResult))
            { 


                $fResult    = New QueryResult($splObject->queryResult[0]);
                $j=0;

                echo "\n---------------------------------------------\n";
                foreach ($fResult as $fplObject)
                {
                    echo "ID: {$fResult->records[$j++]->Id[0]}\n";
                    print_r($fplObject->fields);
                    echo "\n\n";
                }
                echo "\n\n\n\n\n\n";
            }
        }
    }
3
  • I think that you only get the post in users profiles. See salesforce.com/us/developer/docs/api/Content/…. If you want all post to any object you can use FeedItem ( salesforce.com/us/developer/docs/api/Content/…) Also keep in mind that you won't get comments that are in posts older than 24 hs even if the comment was added in the last 24 hs.
    – Acuariano
    Mar 21, 2013 at 19:06
  • @Acuariano Since we do not have control over the users account types (this is just from accepting an application) we cannot query FeedItem directly, so this is the best work around I can come up with. You can prove though that with the OR switch that you CAN get Posts and Comments older than 24hrs by switching the Less (>) than to a Greater than (<) in the OR query. (CreatedDate < YESTERDAY) where Posts are newer than 24hrs but Comments are older than 24hrs. Try running that against a post that has old comments.
    – ehime
    Mar 21, 2013 at 19:17
  • @Acuariano I just tested this by bumping a three month old Post, it works fine. the Silver bullet is searching posts that only have more than one comment for a created date, since CreatedDate could be considered ambiguous in SQL.
    – ehime
    Mar 21, 2013 at 19:28

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .