You need to sign in to do that
Don't have an account?
steven.fouracre
Deactivate flows in a beta package by apex
Using the following code I am able to deactivate a flow via code in any org, but if I use the same code in an org where a package has been installed. although you can still manually deactivate the flow, the code no longer works
Http h = new Http();
HttpRequest req = new HttpRequest();
req.setHeader('Authorization', 'OAuth ' + '{!$Credential.OAuthToken}');
req.setHeader('Content-Type', 'application/json');
req.setEndpoint('callout:Connect_to_this_org/services/data/v43.0/tooling/sobjects/FlowDefinition/<<flow id>>');
req.setMethod('PATCH');
String reqMsg = '{"Metadata": {"activeVersionNumber": 0}}';
req.setBody(reqMsg);
HttpResponse res = h.send(req);
h.send(req);
system.debug('## res1 ' + res.getbody());
Http h = new Http();
HttpRequest req = new HttpRequest();
req.setHeader('Authorization', 'OAuth ' + '{!$Credential.OAuthToken}');
req.setHeader('Content-Type', 'application/json');
req.setEndpoint('callout:Connect_to_this_org/services/data/v43.0/tooling/sobjects/FlowDefinition/<<flow id>>');
req.setMethod('PATCH');
String reqMsg = '{"Metadata": {"activeVersionNumber": 0}}';
req.setBody(reqMsg);
HttpResponse res = h.send(req);
h.send(req);
system.debug('## res1 ' + res.getbody());
I would request you to please confirm if the package is a managed package or not where you are trying to use the code to deactivate the flow so that I can help you more?
And If you are using on a managed package then I would suggest you to please check the below article:
https://salesforce.stackexchange.com/questions/362957/can-we-deactivate-a-flow-from-managed-package
Thank You!
the thing that is strange is the same code used in a normal org works perfectly fine
Http h = new Http();
HttpRequest req = new HttpRequest();
req.setHeader('Authorization', 'OAuth ' + '{!$Credential.OAuthToken}');
req.setHeader('Content-Type', 'application/json');
req.setEndpoint('callout:Connect_to_this_org/services/data/v43.0/tooling/sobjects/FlowDefinition/<<flow id>>#');
req.setMethod('PATCH');
String reqMsg = '{"Metadata": {"activeVersionNumber": 0}}';
req.setBody(reqMsg);
HttpResponse res = h.send(req);
h.send(req);
system.debug('## res1 ' + res.getbody());
This will work even if you have a managed package and have installed the package in an org. With a bit more work you can mass deactivate Flows