developerforce / DataWeaveInApex

Examples for working with DataWeave scripts from Apex.

Home Page:https://developer.salesforce.com/docs/atlas.en-us.apexcode.meta/apexcode/DataWeaveInApex.htm

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

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

About

Examples for working with DataWeave scripts from Apex.

https://developer.salesforce.com/docs/atlas.en-us.apexcode.meta/apexcode/DataWeaveInApex.htm

License:Creative Commons Zero v1.0 Universal


Languages

Language:Apex 84.6%Language:DataWeave 10.8%Language:Batchfile 2.2%Language:Shell 1.9%Language:JavaScript 0.5%