Find your content:

Search form

You are here

Quick way to clear all classes and triggers

 
Share

Long story, but I want to clear all the code from an org. I don't need to clear Visualforce pages (there is only one, and I'm deleting that manually) - just all triggers and Apex classes. Does anyone have a quick way to do it?

I have a feeling that it will involve using Workbench, but I've never tried it so I'm coming here before doing anything with that.

Using the UI and deleting triggers and classes one by one is not an option.


Attribution to: DavidSchach

Possible Suggestion/Solution #1

FinancialForce open sourced a tool we use internally to undeploy everything from an org. You need to invoke it via ant, and it goes above and beyond your needs (also removing objects, static resources, etc). I suspect it's your best bet here.

https://github.com/financialforcedev/df12-deployment-tools


Attribution to: ca_peterson

Possible Suggestion/Solution #2

Here's a way using just the Salesforce-supported tool and no dependencies. Proceed with caution ;-)

  1. create a temporary directory to work in,

  2. download salesforce_ant_29.0.zip and extract into a subdirectory lib/salesforce_ant_29.0

  3. create a file in your temp directory called build.properties containing the following:

    sf.username=username@example.com
    sf.password=passwordandsecuritytoken
    
  4. create another file in the temp directory called build.xml, then cd in there and run ant purge:

<?xml version="1.0"?>
<project name="buildSystem" default="deploy" basedir="." xmlns:sf="antlib:com.salesforce">

    <taskdef uri="antlib:com.salesforce"
                 resource="com/salesforce/antlib.xml"
                 classpath="${basedir}/lib/salesforce_ant_29.0/ant-salesforce.jar"/>
    <property file="build.properties"/>
    <property environment="env"/>

    <target name="purge" description="PURGE TRIGGERS AND CLASSES">
        <!-- Clean up any previous purge -->
        <delete dir="purge" />
        <mkdir dir="purge" />

        <!-- Prepare a wildcard package definition with as many metadata types as possible -->
        <echo file="purge/package.xml"><![CDATA[<?xml version="1.0" encoding="UTF-8"?>
            <Package xmlns="http://soap.sforce.com/2006/04/metadata">
                <types><members>*</members><name>ApexClass</name></types>
                <types><members>*</members><name>ApexTrigger</name></types>
                <version>29.0</version>
            </Package>
        ]]></echo>

        <!-- Retrieve the wildcard package definition -->
        <sf:retrieve
        username="${sf.username}"
        password="${sf.password}"
        serverurl="https://login.salesforce.com"
        retrieveTarget="purge"
        unpackaged="purge/package.xml"
        pollWaitMillis="1000" />

        <!-- Name the package definition -->
        <replace file="purge/package.xml">
            <replacetoken><![CDATA[</version>]]></replacetoken>
            <replacevalue><![CDATA[</version><fullName>Purge</fullName>]]></replacevalue>
        </replace>

        <!-- Re-deploy the now-named wildcard package definition -->
        <sf:deploy
        username="${sf.username}"
        password="${sf.password}"
        serverurl="https://login.salesforce.com"
        deployRoot="purge"
        purgeOnDelete="true"
        pollWaitMillis="1000" />

        <!-- Retrieve by name, giving us an explicit package definition -->
        <sf:retrieve
        username="${sf.username}"
        password="${sf.password}"
        serverurl="https://login.salesforce.com"
        retrieveTarget="purge"
        packageNames="Purge"
        pollWaitMillis="1000" />

        <!--
         ! Trash local components: we only needed them to get an explicit package definition.
         ! Now we turn the explicit package definition into explicit destructive changes, and
         ! blank out the package definition.
         !-->
        <delete includeEmptyDirs="true" dir="purge" includes="**/*" excludes="*.xml" />
        <copy file="purge/package.xml" tofile="purge/destructiveChanges.xml" />
        <echo file="purge/package.xml"><![CDATA[<?xml version="1.0" encoding="UTF-8"?>
            <Package xmlns="http://soap.sforce.com/2006/04/metadata">
                <version>29.0</version>
            </Package>
        ]]></echo>

        <!-- Perform explicit deploy over the top of the org which should delete all components -->
        <sf:deploy
        username="${sf.username}"
        password="${sf.password}"
        serverurl="https://login.salesforce.com"
        deployRoot="purge"
        purgeOnDelete="true"
        pollWaitMillis="1000" />

        <!-- Tidy up after ourselves -->
        <delete dir="purge" />
    </target>
</project>

Attribution to: bigassforce

Possible Suggestion/Solution #3

Using Eclipse to delete classes by one time.


Attribution to: phoenix7788
This content is remixed from stackoverflow or stackexchange. Please visit https://salesforce.stackexchange.com/questions/32689

My Block Status

My Block Content