In our organization we have made few of the class as global class in our sales force org.

The objective of the global class is nothing but to trigger apex batch jobs. Since apex job being async i cannot use it for my automation if i run them in developer console. And we where not allowed to write our automation in test methods.

So we are planning to create a small framework outside sales force using python. There are lot of utility available in python to directly insert, delete, update my sales force record in python. But there is nothing to trigger a job.

I want to do some action in sales force and have to run the jobs and at the end of my job i need to validate the values in my record and this is not possible if i run them in developer console since job are async. So my ask here is there a way to call batch jobs from python.

Thanks, Balaji.

1 Answer 1


There are multiple ways to achieve this.

1) What you can do is create your custom web service and call your batch job in your web service. Once your web service is set up then you can call it from Python (or any where is the world)

Here is link that will tell you how to create custom web service in SFDC.

SOAP web service: https://developer.salesforce.com/docs/atlas.en-us.apexcode.meta/apexcode/apex_web_services_methods.htm

Rest Web Service: https://developer.salesforce.com/page/Creating_REST_APIs_using_Apex_REST

2) Create a temp object and on that object create trigger. In trigger code call the batch job. From Python create insert record in tmp object which will then start the batch.

3) You can use tooling API to execute Anonymous apex block. Pass the apex code that start your batch.

The executeAnonymous API is available at /services/data/v34.0/tooling/executeAnonymous

You need to pass anonymousBody as URL encoded string.

Take a look at. https://resources.docs.salesforce.com/sfdc/pdf/api_tooling.pdf Page 2

Also if are familiar with work beach then use it to explore more on this API.

enter image description here

  • Is there any idea how this is being done in MavensMate, because it allow us to run a chunk of apex code directly in our sales force org. If mm package is created with python then there should be some way to do it. Please correct me if i am wrong. @AtulRajguru9 Dec 15, 2015 at 6:25
  • 1
    MM usage the tooling api to execute apex code. You can use that too. see my updated answer Dec 15, 2015 at 6:41
  • Can you please elaborate more on the "3"rd point you mentioned above. @AtulRajguru9 Dec 15, 2015 at 9:20
  • Thanks a ton @AtulRajguru9 . Now i am able to run my global class through API. I will try to convert them in to python code. Thanks a lot again. Dec 15, 2015 at 11:33

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .