REST API Framework
Client Profile & Description
We delivered as a backend support team for a Salesforce Gold Partner, for one of US government agency.
“We are happy to receive a functional framework to adapt with the needs for submitting API responses for our different business processes.”
Technology Used
Salesforce Suite: Salesforce CRM, Salesforce Platform, Salesforce Web Services
Management: JIRA and Github
Requirements/Problem Statement
A configurable Rest API receiver that can be adjusted to a change in json Structure without changing the underline Apex Code.
Our Solution Design
We Analyzed the Salesforce platform to create an API receiver, the usual way is to Create the wrapper classes that can parse a JSON response in apex using a tool such as ” https://json2apex.herokuapp.com/”.
Once these wrapper classes are generated, the next step is to write a Receiver class where we need to deserialize the input json string using JSON.deserialize() and it will return an instance of the wrapper class.
” Now the limitation here with a Wrapper class approach was that, if a new Name/Value pair is added to the Inbound JSON, the wrapper class has to be updated and also for saving New Values in a Custom field on a Custom object, this assignment has to be added, again a code change.”
Solution in Salesforce
To cater the above problem we Used Custom Metadata instead of the Apex because we can utilize a Custom Metadata to map a json Key (name in Name/value pair) to a Custom Field on a Custom Object.
Now while deserializing the Inbound Json, we have to deserialize it into a Generic type such as Map<String, Object>. Then this Generic Map where we have deserialized the data can be used in conjunction with the metadata records to create/update appropriate Custom field.
In this approach if a new Name/Value pair is added to the inbound JSON, we have to create a new mapping in the custom metadata and no underlying code change Required.
Results/Benefits
We developed a successful extendable Rest API receiver with the above solution as per the client Requirements. Please contact for further Details.
