8

Background:

  1. There is only one version of the process builder exists in sandbox, version number is 1 and it is Active.
  2. I retrieved this process builder using the command sfdx force:source:retrieve --sourcepath=/path/to/flow --targetusername=sandbox (API version is set to 47.0 in sfdx-project.json)

Goal:

Deactivate this process builder by deployment.

Attempt 1:

  1. Changed value for status tag in flow xml to Obsolete and deployed using the command sfdx force:source:deploy --sourcepath=/path/to/flow --targetusername=sandbox

It didn't deactivate the existing version but created version 2 with Inactive status.

Attempt 2:

  1. Changed value for status tag in flow xml to Draft and deployed using the command sfdx force:source:deploy --sourcepath=/path/to/flow --targetusername=sandbox

It didn't deactivate the existing version but created version 2 with Inactive status.

As per the Flow MetadataAPI documentation, status can be either "Obsolete" or "Draft" and both correspond to Inactive status but it seems to be not working.

I ran all of the above commands using the option --apiversion=47.0 but still same result.

2 Answers 2

8

I was able to deactivate process builder as follows:

  1. Retrieved FlowDefinition file for the process builder that I am trying to deactivate using the command sfdx force:source:retrieve --metadata=FlowDefinition:ProcessBuilderApiNameGoesHere
  2. Updated value for tag activeVersionNumber to 0.

    <?xml version="1.0" encoding="UTF-8"?>
    <FlowDefinition xmlns="http://soap.sforce.com/2006/04/metadata">
        <activeVersionNumber>0</activeVersionNumber>
    </FlowDefinition>
    
  3. Did the deployment using the command sfdx force:source:deploy --sourcepath=/path/to/flowDefinitionfile

and it worked(process builder was deactivated).

It would be nice if we can deactivate process builder by just changing value for status tag in actual process builder file(flow xml) itself.

1
  • 1
    n.b. use extra spaces to get code to format inside a numbered list. It's not very intuitive.
    – David Reed
    Mar 18, 2020 at 23:52
1

I think you have basically answered it: You cannot deactivate it by a Metadata API deployment. Just one of those weird quirks Salesforce has put into the API for us.

You MIGHT be able to do it with Tooling API by updating either the Flow or FlowDefinition object. I haven't tested this.

5
  • One can definitely activate using the Tooling API (at least on specific API versions!). I've never tried to deactivate.
    – David Reed
    Mar 18, 2020 at 4:13
  • If we can't really deactivate using metadata API, how do projects using CI/CD achieve this? Just curious..
    – javanoob
    Mar 18, 2020 at 4:30
  • 2
    The honest answer is, "Salesforce is not 100% properly built for CI/CD and this is just one of the things you have to hack / work around"
    – Charles T
    Mar 18, 2020 at 19:54
  • Or, "use scratch orgs for CI/CD".
    – David Reed
    Mar 18, 2020 at 20:39
  • @DavidReed OK but when the change you finally have to merge into your real production org is still something you can't do properly with Metadata API, the fact that you used scratch orgs for CI/CD won't have helped you.
    – Charles T
    Mar 19, 2020 at 12:05

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .