Quick way to clear all classes and triggers

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


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:

    [email protected]
    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>