Newer Version Available
Implementing DataWeave in Apex
DataWeave Namespace
The DataWeave namespace provides classes and methods to support the invocation of DataWeave scripts from Apex. The Script class contains the createScript() method to load DataWeave scripts from .dwl metadata files that have been deployed to an org. The resulting script can then be run with a payload using the execute() method to obtain script output in a DataWeave.Result object. The Result class contains methods to retrieve script output using Script class methods. For more information on these classes and methods, see DataWeave Namespace.
For every DataWeave script, an inner class of type DataWeaveScriptResource.ScriptName is generated. The inner class extends the DataWeave.Script class. You can use the generated DataWeaveScriptResource.ScriptName class instead of using the actual script name via the createScript() method. DataWeave scripts that are currently being referenced via this inner class can't be deleted. To make the generated DataWeaveScriptResource class global, set the isGlobal field in the DataWeaveResource metadata object.
1<?xml version="1.0" encoding="UTF-8"?>
2<DataWeaveResource xmlns="http://soap.sforce.com/2006/04/metadata">
3<apiVersion>58.0</apiVersion>
4<isGlobal>true</isGlobal>
5</DataWeaveResource>The catchable System.DataWeaveScriptException exception is available for error handling. Runtime script exceptions that occur within DataWeave are exposed to Apex with this exception type.
DataWeave scripts support logging using the log(string, value) function. Log messages that originate from DataWeave are reflected in Apex debug logs as DATAWEAVE_USER_DEBUG events, under the Apex Code log category at the DEBUG log level.
Supporting Information
DataWeave 2.4 script syntax is supported in Apex, except for these limitations: Limitations of DataWeave in Apex.
These tools support the development of DataWeave scripts.
- DataWeave Interactive Learning is an online interactive playground that you can use to test your DataWeave scripts.
- DataWeave 2.0 VSCode marketplace extension adds code highlighting and other feature support for editing DataWeave scripts.