function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
Will Jones 18Will Jones 18 

Create Nested JSON string to pass Opportunity Contact Roles

I'm looking to pass all contacts on an opportunity to an external system when an opp is saved/updated. The JSON format is below. What is the best way to achieve this?

Example output:
    [
        {
            "opportunity_contact_role_id":"",
            "contact_id":"",
            "role":"",
            "is_primary":""
        },
        {
            "opportunity_contact_role_id":"",
            "contact_id":"",
            "role":"",
            "is_primary":""
        }
    ]
Ankit Gupta@ DeveloperAnkit Gupta@ Developer
Hi Win

You can create a wrapper class for that and then JSON.serialize method in apex.