Hi there, in this blog we will learn about webhooks. In simple words webhooks are a kind of mechanism to alter system from another system.
Let's understand it using an example - Let's say there are two servers "Server A" and "Server B".
Server A is the source from where we need to send the data and Server B is the target destination for the data. But there is another server database "Server C" in between them, so in end to end integration Server A will be sending data to Server C and Server B will be fetching it from Server C.
To fetch the data Server B will be hitting API request to Server C and will check if the data is available then fetch the data or else return null. Now without webhooks Server B will be continuously hitting API after a timespan to check if Server C is having the data which is not an efficient way as each API will be costing you something.
As a solution we will create a webhook URL and will give it to Server C and tell it that whenever you are having data just send Server B a ping.
Now whenever Server B is receiving a ping it will hit the request to Server B and will fetch the data.
Follow below steps to create a webhook in Salesforce
Step 1: Create Apex Webhook Handler
WebhookHandler.cls
1 2 3 4 5 6 7 8 9 10 11 12 13 | @RestResource(urlMapping='/api/invokeWebhook/*') global with sharing class WebHookHandler { @HttpPost global static void handlePost(){ RestRequest requestContext = RestContext.request; RestResponse responseContext = RestContext.response; //Request //Do something when notification received //For demo I have created an Account Account acc = new Account(Name='Webhook Account 1'); insert acc; } } |
0 Comments