3.33Handling arrays of nested contacts
Now Acme has several contacts:
{
"customerId": "C001",
"companyName": "Acme",
"contacts": [
{
"contactId": "P001",
"firstName": "John",
"lastName": "Smith"
},
{
"contactId": "P002",
"firstName": "Sarah",
"lastName": "Jones"
}
]
}
After creating/upserting Account:
vars.accountId
Now:
%dw 2.0
output application/java
---
vars.originalCustomer.contacts map (contact) -> {
External_Contact_ID__c: contact.contactId,
FirstName: contact.firstName,
LastName: contact.lastName,
AccountId: vars.accountId
}
Output:
[
{
"External_Contact_ID__c": "P001",
"FirstName": "John",
"LastName": "Smith",
"AccountId": "001..."
},
{
"External_Contact_ID__c": "P002",
"FirstName": "Sarah",
"LastName": "Jones",
"AccountId": "001..."
}
]
Then Salesforce:
Upsert Contacts
That's a solid interview scenario.