Using Process Builder to delete lead converted chatter posts

I wanted to use Process Builder + a flow to automatically delete the chatter post generated on an account when a lead is converted. I’ve created both parts, but it doesn’t seem to be working…

Here’s the process builder:

Process Builder Overview Screenshot

It triggers on the “Feed Item” object, when an object is created or edited, with no recursion.

The action group criteria is pretty basic for now, just to test it — with the only condition being FeedItem Type = “Tracked Change”

Process Builder Criteria Screenshot

And the only action is to launch the flow that deletes the record…

Process Builder Action Screenshot

The flow is just one part:

Flow Item Screenshot

Taking the variable ID from the Process Builder and deleting it

Flow Variable Screenshot

Any ideas why this wouldn’t work?

Answer

The problem is that the Process Builder flow never even fires. Even if you remove the criteria and/or change the action, you will not see any activity. Check this document, which states:

Only FeedItems of type TextPost, LinkPost, HasLink, ContentPost, and HasContent can be inserted, and therefore invoke the before or after insert trigger. User status updates don’t cause the FeedItem triggers to fire.

It seems like FeedItems created during Lead Conversion are not on the whitelist included in the above description (as you noted the Type is TrackedChange). I wrote an Apex Trigger on the FeedItem object after insert, and it indeed did not fire either. You’re going to have to trigger on the Account object and find the FeedItems to delete another way. It seems like it should still be possible via Auto-launched Flow.


If triggering is impossible, you can use a pretty simple batch to find the records you want to delete.

public with sharing class DelteLeadConversionTrackedChange
    implements Database.Batchable<SObject>
{
    public Database.queryLocator start(Database.BatchableContext context)
    {
        return Database.getQueryLocator([
            SELECT Type FROM FeedItem
            WHERE Type = 'TrackedChange'
            AND Parent.Type = 'Account'
        ]);
    }
    public void execute(Database.BatchableContext context, List<SObject> scope)
    {
        List<Id> toDelete = new List<Id>();
        for (SObject record : scope)
        {
            String body = (String)record.get('Body');
            if (body.endsWith('converted a lead to this account.'))
                toDelete.add(record.Id);
        }
        Database.delete(toDelete)
    }
    public void finish(Database.BatchableContext context) { }
}

Attribution
Source : Link , Question Author : Matt , Answer Author : Adrian Larson

Leave a Comment