Created
August 18, 2022 11:12
-
-
Save justynroberts/16ba3f19e17247810352e76f5452a1f2 to your computer and use it in GitHub Desktop.
Salesforce Apex Code for triggering Process Automation Webhook and passing data.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
global class PDprocessautomation implements Process.Plugin { | |
global Process.PluginResult invoke(Process.PluginRequest request) { | |
//Add Payload Parameters - 4 payload paramters in this case; Modify for more | |
String item1 = (String) request.inputParameters.get('item1'); | |
String item2 = (String) request.inputParameters.get('item2'); | |
String item3 = (String) request.inputParameters.get('item3'); | |
String item4 = (String) request.inputParameters.get('item4'); | |
//Request | |
Http h = new Http(); | |
HttpRequest req = new HttpRequest(); | |
//Modify to your own endpoint | |
req.setEndpoint('https://rdse.runbook.pagerduty.cloud/api/41/webhook/XXXXXXXX'); | |
req.setMethod('POST'); | |
req.setHeader('Content-Type', 'application/json'); | |
//payload below - Modify payload names if necessary | |
req.setBody('{"email": "'+item1+'","businessunit": "'+item2+'","notes": "'+item3+'","duration": "'+item4+'"}'); | |
HttpResponse res = h.send(req); | |
// return to Flow | |
Map<String,Object> result = new Map<String,Object>(); | |
return new Process.PluginResult(result); | |
} | |
// Returns the describe information for the interface | |
global Process.PluginDescribeResult describe() { | |
Process.PluginDescribeResult result = new Process.PluginDescribeResult(); | |
result.Name = 'PDprocessautomation'; | |
result.Tag = 'Automation'; | |
//Add new list paramaters to be displayed in the UI | |
result.inputParameters = new | |
List<Process.PluginDescribeResult.InputParameter>{ | |
new Process.PluginDescribeResult.InputParameter('item1', | |
Process.PluginDescribeResult.ParameterType.STRING, true), | |
new Process.PluginDescribeResult.InputParameter('item2', | |
Process.PluginDescribeResult.ParameterType.STRING, true) , | |
new Process.PluginDescribeResult.InputParameter('item3', | |
Process.PluginDescribeResult.ParameterType.STRING, true), | |
new Process.PluginDescribeResult.InputParameter('item4', | |
Process.PluginDescribeResult.ParameterType.STRING, true) | |
}; | |
result.outputParameters = new | |
List<Process.PluginDescribeResult.OutputParameter>{ }; | |
return result; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment