Dynamic parsing using custom metadata
In the examples so far, we have let Apex do most of the heavy lifting for us in translating our request body into Apex data types for us to work with. In this section, we will look at how we could do this manually.
We want to be able, at runtime, to determine how we should map the data provided to us to different fields within Salesforce. To do this, we will be using a custom metadata type.
In the following screenshot, you can see the definition for my API Mapping custom metadata type. I have added an additional Target Field text field to the metadata type, so we can create records using the DeveloperName
field to hold the API property, and the Target_Field__c
field to hold the API name of the field to populate:
Figure 14.2 – API Mapping custom metadata type definition
Next, I have created two records to allow us to map the fields we were previously working with in our examples. You can see them in the...