How to set created date for CollaborationGroupFeed in test class in Salesforce

Sample Test Class:

@isTest
private class CollaborationGroupFeedTest {

    static testMethod void test() {
        CollaborationGroup cg = new CollaborationGroup(Name = 'Test', CollaborationType = 'Public');
        insert cg;
        FeedItem FI = new FeedItem(Body = 'Test', ParentId = cg.Id);
        insert FI;
        CollaborationGroupFeed CGrpFeed = [ SELECT Body, Type FROM CollaborationGroupFeed ];
        system.debug('Output is ' + CGrpFeed);
        Test.setCreatedDate(CGrpFeed.Id, System.now.addMonths(-4));
    }

}

Cheers!!!

No comments:

Post a Comment