5

I am attempting to deactivate triggers using the tooling API. I have successfully in a developer ORG. But was unable to do this in a real developer org. Is this a Salesforce tooling api bug?

Here is the basis of the algorithm,

  1. Create a MetadataContainer with a unique Name
  2. save MetadataContainer
  3. Create an ApexTriggerMember setting the Body, MetadataContainerId, ContentEntityId, and Metadata[apiVersion=33.0 packageVersions=[] status="Inactive" urls=nil>]
  4. Modify Metadata["status"]="Inactive"
  5. save ApexTriggerMember
  6. Create/Save ContainerAsyncRequest
  7. monitor container until completed.
  8. display errors if appropriate

In the sandbox, I have confirmed after requerying the Apex enter code hereTriggerMember that the read-only field "Content" looks appropriate. I also confirmed that the MetadataContainerId now points to a ContainerAsyncRequest that has a State of "Completed"

Here are my results, it appears to be a success, but the ApexTrigger is never deactivated ContentEntityId = 01q.............[The ApexTrigger I want deactivated]

Content="<?xml version=\"1.0\" encoding=\"UTF-8\"?>
    <ApexTrigger xmlns=\"urn:metadata.tooling.soap.sforce.com\">
        <apiVersion>33.0</apiVersion>
        <status>Inactive</status>
    </ApexTrigger>" 

Metadata={apiVersion=33.0 packageVersions=nil status="Inactive" urls=nil> attributes=        {type="ApexTriggerMember"
     url="/services/data/v33.0/tooling/sobjects/ ApexTriggerMember/401L0000000DCI8IAO"
  }

}

1 Answers1

0

I think you need to deploy the inactive Trigger from Sandbox to Production. You can't simply deactivate the Trigger in Production. This is true even in the UI.

There are other options, such as using a Custom Setting or Metadata Type to store a Run/Don't Run value. You would query that value in the Trigger to decide whether or not to run it.

https://developer.salesforce.com/forums/?id=906F0000000MJM9IAO

TechingCrewMatt
  • 486
  • 2
  • 7