I have a trigger that posts a ConnectApi.AnnouncementInput, but how do I test that this has been posted, and to the correct chattergroup?

I've created the test collaborationgroup in my test method, but I don't know how I can find the related objects to test the feed has been updated.

Thank you.

Edit: Both methods listed in answers seem to work, but the problem now is why the Advanced Apex Superbadge has implement !Test.isRunning() for the method that holds the functionality of posting the chatter feed.

2 Answers 2


Chatter Announcements are nothing but FeedItem records. You can just query them after creating an announcement in test class

SELECT Body,CreatedById,CreatedDate,HasVerifiedComment,NetworkScope,ParentId,Type FROM FeedItem where createdDate=Today and ParentId=:ChatterGroupID

Most Chatter in Apex methods require access to real organization data, and fail unless used in test methods marked @IsTest(SeeAllData=true).

Make sure you mark your test class seeAllData as true.

src: https://developer.salesforce.com/docs/atlas.en-us.apexcode.meta/apexcode/connectAPI_TestingApex.htm

  • Thank you for your reply. But firstly, you should never (rarely) use seeAllData as true. The whole point of the test is to test your logic on test data so that when you move your package to a new org, it still passes test. This feedItem objects seems good, although it also shows Chatter group creation in the feed.
    – rna7
    Jun 25, 2018 at 12:28
  • I'm also confused about whether during a test, apex will be able to see a chatter group if I created it withing the scope of the test method?
    – rna7
    Jun 25, 2018 at 12:40
  • @rna7 check the link I mentioned. You always use seeAllData as true for testing chatter. Jun 25, 2018 at 13:22

I've come across CollaborationGroupFeed object which can use the ParentId field to connect to chatter group.

You must log in to answer this question.

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