-
Notifications
You must be signed in to change notification settings - Fork 464
FormattingRecipes
Demonstrates various ways to apply formatting using DataWeave scripts in Apex.
Group DataWeaveInApex Recipes
Outputs a list of contacts in JSON with properly formatted dates.
Uses the dw/jsonDateFormat.dwl
DataWeave script.
public static String formatDateInJson(List<Contact> contacts)
Name | Type | Description |
---|---|---|
contacts | List<Contact> | list of contacts to convert into JSON |
String
JSON string
Uses the DataWeave pluralize
function in a script (https://docs.mulesoft.com/dataweave/2.4/dw-strings-functions-pluralize).
Uses the dw/pluralizeFunction.dwl
DataWeave script.
public static String pluralize(String singularWords)
Name | Type | Description |
---|---|---|
singularWords | String | list of singular words as a JSON string |
String
list of plural words as a JSON string
Parses a JSON input and escape properties named after Apex reserved keywords (private, object, currency...).
Full list of reserved keywords: https://developer.salesforce.com/docs/atlas.en-us.apexref.meta/apexref/apex_reserved_words.htm
Uses the dw/reservedApexKeywords.dwl
DataWeave script.
public static String escapeApexReservedKeywords(String jsonInput)
Name | Type | Description |
---|---|---|
jsonInput | String | JSON string with Apex reserved keywords used as properties |
String
JSON string without the Apex reserved keywords