Search code examples
salesforcesalesforce-lightning

Dynamic mapping in Salesforce - generate JSON request for call third-party API


I want to generate JSON string from Account sObject field which also contains other sObject. Please help...


Solution

  • In my experience, the best way to go about this without using middleware is to create a custom metadata type for the API mapping. It will store the JSON key, SObject name, and SObject field.

    You can use that data to generate a dynamic SOQL query and then create a map (Map) that can be serialized.

    The complexity depends on the JSON you need to generate. If you need sub-objects or arrays of objects in the JSON, it can get complicated.