You need to sign in to do that
Don't have an account?
bryano
Creating posts and comments to Chatter groups via Apex
I'm trying to test an apex class that scans a chatter group for posts. I have a query in my class that queries on the CollaborationGroupFeed object. In my test class I have the following code:
Test.startTest(); CollaborationGroup cg = new CollaborationGroup(Name='Test Group', CollaborationType='Public'); insert cg; // Create Chatter Post FeedItem testFeed1 = new FeedItem(Body='Test Feed 1 Post', ParentId = cg.Id, Type='TextPost'); insert testFeed1; // Create Chatter Comment FeedComment testFeed1Comment = new FeedComment(CommentBody='Test Feed 1 Comment', FeedItemId=testFeed1.Id, CommentType='TextComment'); insert testFeed1Comment; // Create Chatter Post FeedItem testFeed2 = new FeedItem(Body='Test Feed 2 Post', ParentId = cg.Id, Type='TextPost'); insert testFeed2; // Create Chatter Comment FeedComment testFeed2Comment = new FeedComment(CommentBody='#answer Test Feed 2 Comment', FeedItemId=testFeed2.Id, CommentType='TextComment'); insert testFeed2Comment; List<CollaborationGroupFeed> feeds = [Select Body from CollaborationGroupFeed]; system.debug('-------------- ' + feeds); Test.stopTest();
When I do a query on CollaborationGroupFeed to confirm the records, it returns 0 records. What am I doing wrong?
The class is written in the new api version. You need to use the IsTest(SeeAllData=true) Annotation.
http://www.salesforce.com/us/developer/docs/apexcode/index_Left.htm#CSHID=apex_methods_system_test.htm|StartTopic=Content%2Fapex_methods_system_test.htm|SkinName=webhelp
All Answers
The class is written in the new api version. You need to use the IsTest(SeeAllData=true) Annotation.
http://www.salesforce.com/us/developer/docs/apexcode/index_Left.htm#CSHID=apex_methods_system_test.htm|StartTopic=Content%2Fapex_methods_system_test.htm|SkinName=webhelp
Thanks arizona. That was the issue.