[SalesForce] How to test that a ConnectApi.AnnouncementInput has been posted to a CollaborationGroup

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.

Best Answer

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

Related Topic