1
curl --location --request PUT 'https://ap17.salesforce.com/services/data/v48.0/sobjects/ApexTrigger/01q2x000000YiNcAAK' \
--header 'Authorization: Bearer 00D2....' \
--header 'Content-Type: application/json' \
--data-raw '{
    "Name": "ContactCreateUpdateDeleteApexTrigger",
    "TableEnumOrId": "Contact",
    "Body":"trigger ContactCreateUpdateDeleteApexTrigger on Contact (after update,after insert, after delete) {            String url = '\''https:endpoint.com'\'';         String content = WebhookClass.jsonContent(Trigger.new, Trigger.old,'\''Contact'\'');         WebhookClass.callout(url, content);          }"
    }'

I am trying to update an existing apex trigger from rest api however the existing trigger is not updated

3
  • Do you get an error message? Nov 9 '20 at 12:42
  • No I am getting 200 response @SanderdeJong Nov 9 '20 at 12:43
  • 1
    Although Apex classes and triggers have the Create and Update field properties, a runtime exception occurs if you try to create or update them using the API. Instead, use the Ant Migration Tool, the Salesforce user interface, or the Salesforce Extensions for Visual Studio Code to create or update Apex classes or triggers. Nov 9 '20 at 13:59
1

You can't update triggers using the sObject API, as it is not an sObject. You need to use a metadata deployment. Most people today prefer to use Salesforce DX, as it is the newest modern tool for deployments, and can deploy from the command line.

8
  • Thank you @sfdcfox I went through the documentation I am still unable my trigger, not sure what I am missing. Could you help me with a curl ? Nov 9 '20 at 16:24
  • @ChrisBlesson You need to create a ZIP file and then deploy it. The URL for this would be on the API endpoint using POST to /services/data/v49.0/metadata/deployRequest. You'll need to read the documentation. I don't use curl regularly, you'll need to use the documentation.
    – sfdcfox
    Nov 9 '20 at 16:52
  • Thank you @sfdcfox Nov 9 '20 at 16:55
  • @ChrisBlesson did you manage to do this? Any example or doc that could point me in the right direction to create a trigger on new Case? Thanks in advance
    – hosseio
    Aug 4 at 9:05
  • 1
    @hosseio it sounds like you need a callout, not a metadata API call. How about this? Why don't you ask a new question, include as much detail as you can, and I'll take a look at it for you.
    – sfdcfox
    Aug 4 at 15:18

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.