<!-- Retrieve an unpackaged set of metadata from your org --><!-- The file ${targetDir}/package.xml lists what is to be retrieved --><target name="retrieve" depends="setup"> <!-- Retrieve the contents into another directory --> <sf:retrieve username="${sf.username}" password="${sf.password}" serverurl="${sf.serverurl}" retrieveTarget="${targetDir}" unpackaged="${targetDir}/package.xml"/></target>

<!-- Deploy the unpackaged set of metadata retrieved with retrieveUnpackaged --><!-- The file ${targetDir}/package.xml lists what is to be depployed --><target name="deploy" depends="setup"> <sf:deploy username="${sf.username}" password="${sf.password}" serverurl="${sf.serverurl}" deployRoot="${targetDir}"/></target>

</project>

Create APEX Class Using Ant

So here is a snippet to include in your build.xml file to generate a blank APEX class.

Now when you run ant like thisant -v -lib . -f build.xml -Dtarget=test -Dobject=Opportunity -Dtype=after createTrigger

you get triggers/OpportunityAfterUpsertTrigger.trigger with this contenttrigger OpportunityAfterUpsertTrigger on Opportunity (after insert, after update) {}

and you get triggers/OpportunityAfterUpsertTrigger.trigger-meta.xml with the necessary meta definition. When you deploy this new class will be pushed to the server.

Create APEX Trigger Using Ant

I have a simple naming convention for my trigger files. Object + Before or After + "UpsertTrigger". For example OpportunityAfterUpsertTrigger works on Opportunity objects after insert or update. I generally only build before or after upsert triggers; meaning I generally have triggers like thistrigger OpportunityAfterUpsertTrigger on Opportunity (after insert, after update) {}
or thistrigger OpportunityBeforeUpsertTrigger on Opportunity (before insert, before update) {}

Inside these triggers I generally collect the objects that need to be worked on and ship them over to another class to do the work and testing.

So here is a snippet to include in your build.xml file to generate a blank trigger.