I have a scenario, you have to do data loading into an object in Production and there's a trigger on the object. How can you disable the Trigger?

We cannot directly disable that in Production Org

Apart from the fact that we can deactivate it using changesets, you can also deactivate it using SFDX. The reason for not using changesets can be as simple as the time it takes to run all the tests.

If the org has a large no of classes then it takes anywhere around 40-45 minutes to execute all the test classes. In that case, we can take the help of SFDX.

These are the steps you need to follow to deactivate a trigger in Production using SFDX.

  • Create a package.xml file to retrieve the metadata of the trigger. You will already be having this file. Only include triggers in the XML file only to retrieve them
  • Authorise the destination org where you want to deactivate the trigger using the command sfdx force:auth:web:login
  • Use the sfdx force:mdapi:retrieve command to retrieve metadata of the trigger using the package.xml file created earlier.
  • Once the metadata file is retrieved, unzip the file, and in the triggername.trigger-meta.xml file change the status from Active to Inactive.
  • Now run the sfdx force:mdapi:deploy command to deploy the changes to the target org.

The basic route that you will be taking here is

  • Fetch the metadata of trigger from the org
  • After fetching it unzip it and it will have a triggername.trigger-meta.xml file.
  • Change the status from Active to Inactive
  • Push the code back to the org

This way you don't have to run all the test classes and etc.

Hope that is helpful!