Capturing API Request

,

After reading this blog post you will be able to capture incoming data before they are committed to the database and display the content in json like structure.

When you want to step into the world of salesforce development, using apex, calling endpoints, triggering APIs, it can be all quite overwhelming. Where to start? What to do? How not to lose your shit?

I found for myself the best way to learn is trying to see what is actually happening in the system. So my goal was always to create as much transparency as possible for the users – but also for me in order to a better job.

At some point I found myself having to manage incoming data from an endpoint a salesforce endpoint that was provided to the frontend IT. They build a form where people could enter data and it was then being send to a salesforce endpoint that created a record.

So far so good – except for the part it kept failing and the data was gone and I had no chance of recovery as I had no clue what was sent in the first place.

Being familiar with postman – which is something I can encourage everyone one to figure out in this line of work – I play around with how the endpoint works and what was happening. My goal was simple:

I wanted to see what data actually was sent to an endpoint and I wanted to capture the input / request body in salesforce. Since it is a standard salesforce endpoint there is not really much we can do on the sending point of things. I could do is get creative on the receiving end.

Here is what we have to deal with:

  • I can not change the way the endpoint works as it is a default salesforce endpoint
  • I have no control over the form the Frontend team build (thanks for not involving me)
  • So all I can do is capture the request that is being send to salesforce before anything funky happens

Here is how we solve this:

  • Create a custom object to capture incoming API requests
  • Create an apex trigger (before insert) to capture the incoming data
  • Build a fancy LWC to display the incoming data properly and avoid an otherwise soon to be visit at the eye doctor as non structured json give you eye cancer

The final result:

How did I get there?

Create a custom object to capture incoming data from the endpoint:

Name: API_Request__c

Create an apex trigger to capture the before insert result: https://salesforcepanda.com/before-insert-trigger/

Create a LWC to transform the field data into formatted json: https://salesforcepanda.com/jsonviewer-lwc/

Leave a Reply

Your email address will not be published. Required fields are marked *