0

This is my scenario. I have a Oauth2 app in which I am getting Cases for the connected user. In the initial setup, after getting initial Cases from a custom query, I would like to create on Salesforce a trigger for when a new Case is created, and in this trigger call my API with the Case information that is relevant to my app. It is important to do this in real time (this is why I am thinking on a trigger) and not being asking, like a cronjob. How can I accomplish this?

I have been taking a look at metadata api (ApexTrigger), but it seems that I need a callout? Not even know what this is.

Can anyone point me in the right direction, please? Not sure if this something that I can accomplish, documentation is huge.

I am using Go, but this is just FYI, I don't think this is quite relevant.

Any help would be much appreciated.

2

2 Answers 2

3

Dynamically creating a Trigger is the most dangerous, and among the worst, ways to accomplish data synchronization. You should investigate features like

While creating and deploying a Trigger via the Metadata API is possible, data sync triggers are not easy to write in a way that is resilient to volume. As an external data consumer, it's wiser to use an API-driven or event-driven approach.

1
  • Thank you! I will look into the change data capture doc, in a brief look it sounds like a real time event. At the end what I need is to get the case in my API when it is created in Salesforce. Pls let me get back to you when I have something :)
    – hosseio
    Commented Aug 4, 2021 at 17:16
1

You just need to create a package, and have an administrator install the package. It's not typical to create metadata directly in an org, unless you have a specific use case (like DLRS dynamic trigger creation). You could have your app redirect to the install URL, and the administrator would complete the setup by using the installation wizard. As a bonus, you don't need to validate code coverage or trigger a Run All Tests (required for deploying metadata to production orgs). It is strongly not recommended that you deploy metadata directly to production anyways. You can also use SFDX if you have a valid API token, which you can install on your server rather easily if you can support NodeJS.

1
  • Thanks! This looks like a manual action from my users in their Salesforce account, doesn't it? If so unfortunately this is something I cannot do
    – hosseio
    Commented Aug 4, 2021 at 17:20

You must log in to answer this question.

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