Notes on Salesforce Apex Triggers, suggestion for the ability for sources to reference templates / files

This topic was automatically generated from Slack. You can find the original thread here.

Jay Vercellone : Hello!
I am extending a discussion I had with during the weekend related to a new use case that might be worth looking into.

The use case came up while working on the Salesforce integration. Salesforce provides webhook customisation through “Apex Triggers” [1], which is a bit more complicated than creating/deleting webhooks through a REST API endpoint.

An Apex trigger is basically custom code written in Apex [2] (it’s a programming language built by Salesforce) that is sent and stored in your Salesforce account, and that is executed whenever a certain event occurs. Think of them as a “stored procedure”.
Triggers can contain arbitrary code, which must include logic to serialize data into JSON, post the data to a predefined HTTP endpoint, etc.

For the Salesforce integration I’m working on, I had the idea of having some templates for the Apex triggers, and render those templates with specific data determined by the user.
For example, a template would look like this:

trigger PipedreamNew{{sObject}} on {{sObject}} ({{eventTypes}}) {
    String endpointUrl = '{{endpointUrl}}';
    for (Object item : Trigger.New) {
        String content = Webhook.jsonContent(item);
        Webhook.callout(endpointUrl, content);

The parameters here would be sObject, eventTypes and endpointUrl