To Top
Salesforce Integration Services

SALESFORCE WEBHOOKS: YOUR GUIDE TO REAL-TIME DATA INTEGRATION AND MORE

Publish date:

In today’s connected digital world, seamless communication between systems is crucial for running business operations efficiently. Custom integrations enable systems to send data out of Salesforce, but what if those external systems need to send data back into Salesforce in real time?

Sometimes, it may not be possible to change those external systems to use the existing Salesforce APIs for sending data back. In such cases, webhooks can be helpful.

What Are Webhooks?  

Webhooks are a unique method for systems to communicate without requiring ongoing interaction. Instead of a system fetching data, webhooks enable a system to send a request to a URL when a specific event occurs, such as creating or updating a record.

In simple terms, webhooks are a mechanism that enables one system to notify another about an event, allowing the receiving system to respond accordingly. For Salesforce, this means providing a URL that can listen for and handle events from other systems.

Configuring a Webhook  

Setting up a webhook in Salesforce can be challenging at first because there is no dedicated section in Setup for this task. However, you can use Salesforce Sites or Experience Cloud to create a public URL for the external system that doesn't need authentication.

Here are the basic steps to create a webhook using a Salesforce Site:

  1. In Setup, utilize the Quick Find tool to access the “Sites and Domains > Sites” section.  

  2. Create a new site and give it a label relevant to the webhook you intend to establish. You can leave all other settings unchanged.  

  3. Note the site's “Domain Name” and “Path” in the “Custom Urls” list, as you will need this information to invoke the webhook.  

  4. Develop an Apex class that will function as the webhook handler. This class must fulfill the following criteria:  

    • It should be global.  

    • It needs to be annotated with @RestResource(urlMapping= ‘myUrlEndpoint’), which specifies the URL path that triggers this handler.  

    • It must include a method annotated with @HttpPost, which is called when the URL is accessed. This method can receive parameters or use RestContext to retrieve the body of the incoming request.  

    • It may optionally have a return type to send data back to the caller.

  • Return to the site settings, select “Public Access Settings,” and grant the guest user permission to call this class.  

  • Activate the site

Following these steps will establish a webhook that can be triggered by sending an HTTP POST request to “https://sitedomainurl+path/services/apexrest/apexUrlMapping.”

These steps outline the basics of setting up a webhook. However, you need to think carefully about managing the data you receive from the webhook. You should pay attention to its structure, handle errors properly, and ensure security. These elements are all crucial for any webhook.

Security  

Setting up a Salesforce Site or using Experience Cloud gives us a public URL. This URL allows users to access data and run automation within the organization. Because of this, we need to be very careful. Mistakes in setting permissions or in the code we use can accidentally expose sensitive data.

To make our open endpoint safer and to protect our webhooks, we should follow several steps and consider some essential factors:

1. Access Control:

  1. Authenticating a webhook can be challenging because webhooks typically do not utilize standard authentication methods, such as OAuth. However, we can still control access to our endpoint using other methods.
    1. Only allow specific IP addresses to use the webhook. If an unknown IP attempts to access it, return a 401 response.

    2. Check the webhook for authentication or "secret" headers. These headers show that the request is coming from a trusted source. 

2. Guest User Profile Permissions: Always grant your guest user only the necessary permissions to perform their job. This is called the principle of least privilege. By limiting access, you lower the risk of data leaks because the webhook can’t expose what it can’t access. It’s even better to have one site and guest user for each webhook you need. This way, each webhook can only access what it specifically requires.

3. Input Validation and Sanitization: When using webhooks, we receive data from sources that may not be trustworthy. It's essential first to verify that the data matches our expectations. For example, when updating an account record, we should ensure that the input only contains the fields we plan to update. We also need to clean the data before using it, especially if we’re going to search for a record based on that data. Validating and sanitizing the data can help prevent common types of attacks.  

4. Error Handling: If an unexpected error occurs in our Apex handler, we should catch it and respond accordingly. Sometimes, we may encounter a recoverable error, allowing us to continue smoothly. At other times, we may experience an unexpected error that prevents code execution from continuing. In such cases, we should still catch the error and return a generic 500 status. It is essential because uncaught errors could reveal details about our code and unintentionally expose data.

Adding these measures to your webhook setup can significantly improve the security of your exposed endpoints and reduce potential risks.

It's also important to remember that security is an ongoing effort. Stay vigilant for potential attack points and regularly update your security protocols.

Summary  

Webhooks enable different systems to communicate and transfer data into Salesforce in real time. It's essential to prioritize security when setting up webhooks. Planning can help you follow basic security principles, such as granting only the necessary access to users and regularly assessing the risks.

When you manage security effectively, you can fully leverage real-time communication and significantly enhance your systems.

Looking to streamline your business processes and improve team collaboration? Partner with Codleo Consulting, a trusted Salesforce partner offering comprehensive Salesforce integration services across the USA, UAE, and India. Whether you’re integrating Salesforce with Webhooks or other platforms, our certified experts make the process seamless—automating manual tasks, enhancing data accuracy, and saving valuable time.

As a leading Salesforce integration partner, we go beyond just implementation. Our services include ongoing Salesforce support, strategic Salesforce staffing, and tailored solutions that drive real results. From improving security and version control to accelerating your go-to-market strategy, Codleo has the tools and experience to help your business thrive.

Let us handle the technical complexities, so you can focus on what truly matters—growing your business.

Contact us today to start building a brighter and more efficient future!

Also Read: A COMPREHENSIVE GUIDE TO START INTEGRATING DRUPAL WITH SALESFORCE

About the Author

author
Arun Jangra

Arun is a 5x Salesforce certified Developer with an overall work experience of 9 years. He is very organised and uses his skill set & knowledge to deliver out-of-box solutions.

Talk To Us

ARE YOU LOOKING FOR PROFESSIONAL ADVICE FOR YOUR NEW BUSINESS