Yogesh
Yogesh

Reputation: 895

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.

Upvotes: 1

Views: 1652

Answers (1)

Daniel Ballinger
Daniel Ballinger

Reputation: 13537

You can create a new ApexTrigger using the Tooling API or update an existing one using ApexTriggerMember.

There is an example of creating a Trigger using the REST API in How do I use the Tooling API to create a new Apex Trigger?

$ curl -H 'X-PrettyPrint: 1' -H 'Authorization: Bearer 00D...' \
    -H 'Content-Type: application/json' \
    -d '{ "Name" : "TestTrigger", \
          "TableEnumOrId" : "Opportunity",\
          "Body" : "trigger TestTrigger on Opportunity (after insert){}" }' \
    https://na15.salesforce.com/services/data/v27.0/sobjects/ApexTrigger
{
  "id" : "01qi0000000DKwyAAG",
  "success" : true,
  "errors" : [ ]
}

Upvotes: 3

Related Questions