+ Start a Discussion
Bhushan2710Bhushan2710 

TestMethod fails for Chatter FeedItem

Hi ,

 

I have test method where i try to get the Feeditem of type trackedChange which is automatically created when we update a field value that is being tracked via feedTracking. But the test method is not able to get that feedItem record. Even tried with lowering the version, but no results. Can someone help?

Following is the testmethod: -

static testmethod void mytest(){
        Account acc = new Account(Name = 'TestAccountBhushan',Phone = '040-754-7845');
        insert acc;        
        acc.Phone = '040-123-4567';            
        update acc;      
        List<FeedItem > txtFeedItem = [SELECT Id,
               ParentId FROM FeedItem Where ParentId=: acc.Id];
               System.assertEquals(1, txtFeedItem.size());
        }

Puja_mfsiPuja_mfsi

Hi,

use the isTest(SeeAllData=true) annotation to grant test classes  access to all data in the organization

 

@isTest(SeeAllData=true)
public class TestDataAccessClass {

    static testmethod void mytest(){
        Account acc = new Account(Name = 'TestAccountBhushan',Phone = '040-754-7845');
        insert acc;        
        acc.Phone = '040-123-4567';            
        update acc;      
        List<FeedItem > txtFeedItem = [SELECT Id,
               ParentId FROM FeedItem Where ParentId=: acc.Id];
               System.assertEquals(1, txtFeedItem.size());
        }

}

 

Please let me know if the issue persist.if this post helps you the please give kudos(click on star at left) and mark it as a solution.

Bhushan2710Bhushan2710

I have tried with this, sitll it fails.

Puja_mfsiPuja_mfsi

Hi,

Please post me your trigger where the feed item is automatically created when account record is updated.

Bhushan2710Bhushan2710
This feedItem records in not created via any trigger. This is automaticaly created by salesforce when u enable feed tracking for a object.
Puja_mfsiPuja_mfsi

You need to update those fields of account for which you Enable Feed Tracking.

i.e. if you enable feed tracking for phone field only then it creates feedItem record.

Bhushan2710Bhushan2710
I have enabled feedtracking for phone on account, and thats what i am doing . You can replicate this an check with this code.

Thanks,
Bhushan
Puja_mfsiPuja_mfsi

It means Feed tracking is not working in test class because " Test methods does not actually commit  data,so  Feed Change records is not created."

 Please visit

http://www.salesforce.com/us/developer/docs/apexcode/Content/apex_testing_unit_tests.htm

Bhushan2710Bhushan2710
Ok got it Tracked changes for a record (FeedTrackedChange records) in Chatter feeds aren't available when test methods modify the associated record!!

Thanks for help!