+ Start a Discussion
LoneStar69LoneStar69 

running Anonymous apex thru ANT

Guys,

I am looking to execute anonymous apex code thru ANT scripts.

Ended up with this -

<!-- Import macros --><!-- created ant-salesforce.xml using code from https://gist.github.com/afawcett/5843110 -->
<import file="C:\apache-ant-1.9.6-bin\apache-ant-1.9.6\lib\ant-salesforce.xml"/>
<target name="anonyscrpt">
<executeApex username="${sf.username}" password="${sf.password}" sessionId="${sf.sessionId}" serverurl="${sf.serverurl}" maxPoll="${sf.maxPoll}" rollbackOnError="true">
<![CDATA[
 <My Script goes here>
            ]]>
</executeApex>
</target>

But gives error -

[taskdef] Could not load definitions from resource net/sf/antcontrib/antlib.xml. It could not be found.
BUILD FAILED
The following error occurred while executing this line:
C:\apache-ant-1.9.6-bin\apache-ant-1.9.6\lib\ant-salesforce.xml:20: taskdef class org.missinglink.ant.task.http.HttpClientTask cannot be found
 using the classloader AntClassLoader[]

Is this the correct way?

Appreciate if somebody can outline the process of doing this.
Thanks for your help.
Andy BoettcherAndy Boettcher
What are you trying to do?  Anonymous APEX isn't done via the metadata API - which is what ANT's typical use case is.  You're more looking for the functionality that that Force.com CLI has.  https://force-cli.heroku.com/
LoneStar69LoneStar69
Hi Andy,

Just to make sure i understand correctly, are you saying that i cannot use ANT to run anonymous apex in the target?
As a part of deployment I am trying to insert test data into the custom objects.
Esteve GraellsEsteve Graells
No, What Andy is saying is that is not common running APEX on ANT scripts. But, sometimes we need to do it, for instance, unschedule/schedule a class for a job. @LoneStar69 you can run Apex using 3rd party libraries like forceflow (https://github.com/eroispaziali/ForceFlow)