function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
chris_centrachris_centra 

Do automated Chatter posts happen in test coverage?

When a Lead is Converted and the resulting Contact is attached to an existing Account, an automated Chatter post is created on the Account (Type=TrackedChange).  I wrote a Trigger on Account to automatically delete that Chatter post as soon as it is created.  Works great.  I'm writing test coverage now, but it appears that the automated Chatter post is NOT being created when I do the Lead Conversion in the test coverage context.  Is anyone familiar with this?  Is there a way to make the automated Chatter post appear, or does this simply not happen in test coverage?
Best Answer chosen by chris_centra
Paul B [SalesForce]Paul B [SalesForce]
Chris you are right about the DisableFeedTrackingHeader, I thought it was also exposed in Apex. 

It appears that Apex tests do not commit changes to the DB and without committing changes to the DB the Feed Tracked Change will not be generated. It doesn't seem like it will be possible to write a test for this apex trigger. 

All Answers

Paul B [SalesForce]Paul B [SalesForce]
That is because Feed Tracking is not enabled on that entity in the test org. You can prevent the TrackedChange chatter post from being created by turning off Tracked Changes on that field. 

https://help.salesforce.com/articleView?id=collab_feed_tracking_overview.htm&type=5
chris_centrachris_centra
Thanks for your response.  However Feed Tracking is enabled on Account in the org where I'm doing development.  When I do a manual test through the UI (create Account, create Lead, convert Lead - linking Contact to Account) - the automated Chatter post does get created.  But when I do those same steps in test coverage, the automated Chatter post does not get created (I query AccountFeed, but there are zero results).  Any idea why?
 
Paul B [SalesForce]Paul B [SalesForce]
I am looking into why you are seeing something different between the Test and the manual steps. However I would suggest you just disabled feed tracking on that field, it would be easier and prevent you from having to maintain the trigger.
Paul B [SalesForce]Paul B [SalesForce]
So its very possible you have DisableFeedTrackingHeader set to true. Here is the documentation for modifying that property.  (https://developer.salesforce.com/docs/atlas.en-us.api_tooling.meta/api_tooling/sforce_api_header_disablefeedtracking.htm)
chris_centrachris_centra
Thanks so much for your response, Paul.  For your June 4 response, Feed Tracking is enabled on Account, but it is disabled on all fields.  There isn't really a specific field that is in-play here.  It's just automated sfdc Chatter functionality - when a Lead is converted to a Contact and that Contact is associated with an existing Account, a Chatter post is created automatically (if Feed Tracking is enabled on Account).  I could disable Feed Tracking on Account, but then there would be no Chatter feed on Account...

For your June 5 response, it seems that DisableFeedTrackingHeader doesn't apply to Apex code, right?  It seems to apply to APIs and web services, but I'm just talking about test coverage.  Or maybe I'm not following your thinking?
Paul B [SalesForce]Paul B [SalesForce]
Chris you are right about the DisableFeedTrackingHeader, I thought it was also exposed in Apex. 

It appears that Apex tests do not commit changes to the DB and without committing changes to the DB the Feed Tracked Change will not be generated. It doesn't seem like it will be possible to write a test for this apex trigger. 
This was selected as the best answer
chris_centrachris_centra
Paul - I agree - I think I'm out of luck on this one.  Thanks again for your time!!