BookatlasTwo-Day MuleSoft → Salesforce Bootcamp
15 / 18 · Module 18 — Interview Coding Scenarios · filtered: cheatsheet← prev⊞ allnext →

18.4Scenario 3 — Map an array

Prompt:

“You receive an array of Contacts. Convert them to Salesforce Contacts.”

Input:

[
  {
    "id": "P001",
    "firstName": "John",
    "lastName": "Smith",
    "email": "john@example.com"
  },
  {
    "id": "P002",
    "firstName": "Sarah",
    "lastName": "Jones",
    "email": "sarah@example.com"
  }
]

Write:

%dw 2.0
output application/java
---
payload map (contact) -> {
    External_Contact_ID__c: contact.id,
    FirstName: contact.firstName,
    LastName: contact.lastName,
    Email: contact.email
}

If Account ID is already stored:

%dw 2.0
output application/java
---
payload map (contact) -> {
    External_Contact_ID__c: contact.id,
    FirstName: contact.firstName,
    LastName: contact.lastName,
    Email: contact.email,
    AccountId: vars.accountId
}

This one is worth memorizing exactly.