3.32A realistic Salesforce Account + Contact transformation
Input:
{
"customerId": "C001",
"companyName": "Acme",
"phone": "3055551234",
"billing": {
"city": "Orlando",
"state": "fl"
},
"contact": {
"firstName": "John",
"lastName": "Smith",
"email": "john@acme.com"
}
}
Account transformation:
%dw 2.0
output application/java
var customer = payload
---
[
{
External_Customer_ID__c: customer.customerId,
Name: customer.companyName,
(Phone: customer.phone)
if (customer.phone != null),
(BillingCity: customer.billing.city)
if (customer.billing.city != null),
(BillingState: upper(customer.billing.state))
if (customer.billing.state != null)
}
]
After Account is created, save:
vars.accountId
Then Contact transformation:
%dw 2.0
output application/java
var customer = vars.originalCustomer
---
[
{
FirstName:
customer.contact.firstName,
LastName:
customer.contact.lastName,
Email:
customer.contact.email,
AccountId:
vars.accountId
}
]
This is very close to something you might actually implement.