function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
Yogesh KambleYogesh Kamble 

How to create Apex trigger and apex class using Rest API?

I am trying to integrate my app with salesforce and I am using Rest API using Python. Following things I am implementing

1. Any user of Salesforce from any domain integrate with my app who is registered on my app.

2. Once user integrate app with salesforce I will get access token which I will use in Rest API call.

3. I want to create Apex trigger in salesforce on behalf of user which will call my app API.

I am stuck at point 3 because I am not finding documentation for creating Apex trigger using Salesforce Rest API.

Also I want to know what are the permission levels for Apex Trigger and Apex class ? For example:

1. If user is integrating salesforce with my app and he is sales person and  not administrator then still he can create trigger and classes?

2. If my app ask for salesforce credential and user enter credential of salesforce which is in production  then still my app create apex trigger and apex class on behalf of user?  
Wizno @ ConfigeroWizno @ Configero
This example shows Apex to create an ApexPage, but from python it will be a matter of sending the request to the correct endpoint. 

You'll need to send a JSON payload to the correct enpoint with the correct details, for ApexTrigger see here: http://www.salesforce.com/developer/docs/api/Content/sforce_api_objects_apextrigger.htm
 
private void setRestPostUrl(){
		String sfdcUrl = (String)URL.getSalesforceBaseUrl().toExternalForm();
		String apiPath = '/services/data/v30.0/sobjects/ApexPage';
		restPostUrl = sfdcUrl+apiPath;
}


sfdcURL would be: "naXX.Salesforce.com", where XX is the instance (na1, na2, na3...)
apiPath: the last part 'ApexPage' is what you'll need to modify. For Triggers: ApexTrigger, for classes: ApexClass.

So you'll need your OAuth token, and send your payload to: https://na10.salesforce.com/services/data/v30.0/sobjects/ApexTrigger
(You'll set a Header as 'Authorization' with the OAuth token.)
Yogesh KambleYogesh Kamble

Thanks for Answer. it's really useful.

I also want to know about permission level of Apex trigger and Apex class

1. If user is integrating salesforce with my app and he is sales person and  not administrator then still he can create trigger and classes?

2. If my app ask for salesforce credential and user enter credential of salesforce which is in production  then still my app create apex trigger and apex class on behalf of user?  

osf_teamosf_team
Hi Yogesh,

Did you get the answers to the following questions:

1. If user is integrating salesforce with my app and he is sales person and  not administrator then still he can create trigger and classes?

2. If my app ask for salesforce credential and user enter credential of salesforce which is in production  then still my app create apex trigger and apex class on behalf of user?

I am working on creating Apex Trigger and Apex classes dynamically and my requirements are almost similar to what you have mentioned above. I am also trying to search for the limitations that are exposed when the Apex Trigger and Apex Classes are created dynamically (In my case I am using Metadata API tp create them dynamically)

Thanks
Shalindra Singh
thejeswar reddythejeswar reddy
Hi Yogesh,
I'm working on the same thing as you. I would like to integrate salesforce with other applications for my customers, so that if any lead or contact creates in Salesforce I should get an update. I had found some url 
https://github.com/jamesward/salesforce-webhook-creator/blob/master/app/utils/ForceUtil.scala for creting webhook. I'm working on java. Could you please let me know if you find any soulution.