Skip to content
This repository has been archived by the owner on Feb 12, 2024. It is now read-only.

Latest commit

 

History

History
69 lines (36 loc) · 3.8 KB

README.md

File metadata and controls

69 lines (36 loc) · 3.8 KB

Warning

The content of this repository has been merged into the Apex Recipes sample app.

DataWeave In Apex

Examples for working with DataWeave scripts from Apex.

This functionality is GA in Winter `24.

For feedback and questsions, please see the DataWeave in Apex Trailblazer community group.

If you want to experiment with the possibilities of DataWeave scripts, there is the interactive DataWeave playground.

The DataWeave extension for Visual Studio Code is available and syntax highlighting other additional tooling support.

Slides for the Dreamforce '22 Presentation Unleash Powerful Data Transforms in Apex with DataWeave

Basic Setup

  1. Create a scratch org.
  2. Push the source to the scratch org - requires SFDX CLI 7.151.9+

Examples

Hello World

See HelloWorldTest.cls for a minimal version for calling a DataWeave script from Apex that only logs "Hello World".

CSV to JSON

The following example is from the Dreamforce `21 Develop Enterprise Applications with Apex presentation and starts at the 15 minute mark.

See CsvToJsonConversionTest.cls for an example of transforming CSV data stored in a static resource to a JSON string.

CSV to JSON - alternative separator

See the csvSeparatorToJson() method in CsvToJsonConversionTest.cls for an example of transforming CSV data using ; as the separator to a JSON string.

CSV to POTATO

See the convertCsvToObjects() method in CsvToObjectTest.cls for an example of transforming CSV data directly to an Apex POTATO (Plain Old Typed Apex Transient Object - Apex equivalent of a POJO)

Script error handling

See ExceptionHandlingTest.cls for an example of handling an exception orginating from a DataWeave script execution

Object Processing

See ObjectProcessingTest.cls for examples of passing objects to and receiving objects from DataWeave scripts.

Multiple Inputs

See MultipleInputsTest.cls for an example of handling multiple inputs to a single DataWeave Script.

Built in Functions

See PluralizeTest.cls for an example of using DataWeave built in String functions

Dynamic JSON Mapping

See DWJsonToSObjectsListTest.cls for the example from TDX '22 of dynamic JSON mapping to sObjects

JSON DateTime formatting

See JsonDateFormatTest.cls for an example of custom DateTime formatting in JSON output.

Apex Reserved Keywords

See ReservedKeywordTest.cls for an example of handling reserved Apex keywords