You need to sign in to do that
Don't have an account?
Jason Dodds CodeScience
Delete paused Flow interview from Apex
Using Process Builder, I have a series of Processes(Flows) that execute in 2 days, 4 days, etc (email campaign). if certain criteria (call it Criteria A) are met. The problem with this approach (other than not having the ability to create multiple schedules in a single process) is that a process/flow is in a "paused interview" state until the delay time (2 days) and the filter criteria (Criteria A) are met. While this technically solves my business scenario (don't execute the flow if the user has done X), it results in all of the resulting flows to remain in the "paused interview" state indefinitely. There is a limit of 30K "paused interviews" at one time, so my question is "how do I progammatically clean-up interviews that I do not need to run any longer?" I don't see any Apex method for removing these via a scheduled batch or other means.
We are using the Flows to create records that drive transactional emails, otherwise this process is perfect for a time-based Workflow. Given the lack of functionality to create a record or call a headless flow from time-based workflow, I'm at a loss finding another route for doing this declaratively.
Thanks,
Jason
We are using the Flows to create records that drive transactional emails, otherwise this process is perfect for a time-based Workflow. Given the lack of functionality to create a record or call a headless flow from time-based workflow, I'm at a loss finding another route for doing this declaratively.
Thanks,
Jason
Hi Derek. To answer your question, no, I never figured this out. I'm not sure, but I think in the last release you are allowed to have multiple schedules for an action and it looks like if a process doesn't meet the triggering criteria, the schedule action is dropped from the queue according to this doc (https://help.salesforce.com/HTViewHelpDoc?id=process_limits_scheduled.htm&language=en_US):
That should reduce the overall number of paused interviews, but I didn't do any more research on programmatically removing those via Apex. Good luck, and let me know if there is anything else I can help out with.
Currently - my process is set to only run when created. So it looks like I need to figure out a way to tweak so that it can run when Created or Edited.
Pass the flow Ids into the method one by one. you can create a batch, or limit the loop by 10. (number of apex callout per transaction)
public void deleteFlow(Id Ids)
{
//HTTP Request
HttpRequest request = new HttpRequest();
request.setHeader('Authorization', 'Bearer ' + UserInfo.getSessionID());
request.setHeader('Content-Type', 'application/json');
request.setEndpoint(URL.getSalesforceBaseUrl().toExternalForm()+'/services/data/v45.0/tooling/sobjects/Flow/'+ids);
request.setMethod('DELETE');
//HTTP Response
Http poll = new Http();
HttpResponse res = poll.send(request);
System.Debug('**** flow Response: ' + res.getBody());
}
Query to get flow :
SELECT DefinitionId,id,Status,VersionNumber,MasterLabel from Flow where VersionNumber >1 AND Status ='Obsolete'
This will get you all inactive flow, modify accordingly.