+ 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.