Skip to content

Examples for working with DataWeave scripts from Apex.

License

Notifications You must be signed in to change notification settings

anand13s/DataWeaveInApex

 
 

Repository files navigation

DataWeave In Apex

Examples for working with DataWeave scripts from Apex.

This functionality is currently in Dev Preview in Winter '23. It can be selectively enabled in scratch orgs.

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.

Basic Setup

  1. Create a scratch org with the "DataWeaveInApex" scratch org feature. See /config/project-scratch-def.json as an example
  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.

Resources

License

Code of conduct

Security policy

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • Apex 88.0%
  • DataWeave 11.5%
  • JavaScript 0.5%