Newer Version Available

This content describes an older version of this product. View Latest

Implementing DataWeave in Apex (Beta)

Create DataWeave scripts as metadata and invoke them directly from Apex. Use class methods and exceptions in the DataWeave namespace to load and execute the scripts.

This feature is a Beta Service. Customer may opt to try such Beta Service in its sole discretion. Any use of the Beta Service is subject to the applicable Beta Services Terms provided at Agreements and Terms. You can provide feedback and suggestions for the DataWeave in Apex feature in the Trailblazer Community. The beta release of DataWeave in Apex supports packaging of DataWeave scripts within a namespace. However, you can only access scripts within a package, not across different namespaces.

Note

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.

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 (Beta).

These tools support the development of DataWeave scripts.