Skip to content

Instantly share code, notes, and snippets.

@atskimura
Last active February 26, 2024 12:12
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save atskimura/da96c75c7a0f64d62893e6337c344c79 to your computer and use it in GitHub Desktop.
Save atskimura/da96c75c7a0f64d62893e6337c344c79 to your computer and use it in GitHub Desktop.
// CSV data for Contacts
String inputCsv = 'first_name,last_name,email\nCodey,"The Bear",codey@salesforce.com';
DataWeave.Script script = new DataWeaveScriptResource.csvToContacts();
DataWeave.Result dwresult = script.execute(new Map<String, Object>{'records' => inputCsv});
List<Contact> results = (List<Contact>) dwresult.getValue();
Assert.areEqual(1, results.size());
Contact codeyContact = results[0];
Assert.areEqual('Codey', codeyContact.FirstName);
Assert.areEqual('The Bear', codeyContact.LastName);
Assert.areEqual('codey@salesforce.com', codeyContact.Email);
%dw 2.0
input records application/csv
output application/apex
---
records map(record) -> {
FirstName: record.first_name,
LastName: record.last_name,
Email: record.email
} as Object {class: "Contact"}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment