DataWeave Resources are not authored in the Salesforce UI. You write the .dwl file in your IDE, deploy it as metadata, and then call it from Apex. The Setup page is for inspection only.
- Create the .dwl file
In your SFDX project, add force-app/main/default/dw/MyScript.dwl. Include the metadata XML stub MyScript.dwl-meta.xml that declares the API version. The DataWeave Extension for VS Code provides syntax highlighting and validation.
- Write the transformation
Define inputs in the directive section (%input payload application/json), declare the output format (%output application/json), and write the transformation body. Start with a small known input and the desired output, then evolve the script to bridge them.
- Deploy through Salesforce DX
Run sf project deploy start --source-dir force-app/main/default/dw. The deploy creates or updates the DataWeaveResource metadata. Confirm at Setup, then DataWeave Resources, that the new entry appears with the expected version.
- Call the script from Apex
Build the input map (Map<String, Object> inputs = new Map<String, Object>{'payload' => myPayload}). Create the script (Dataweave.Script s = Dataweave.Script.createScript('MyScript')). Execute it (Dataweave.Result r = s.execute(inputs)). Read the output (Object value = r.getValue()).
- Handle errors
Wrap the execute call in try/catch for Dataweave.ScriptException. The exception's message includes the line number in the .dwl source, which makes debugging much easier than chasing JSON parse failures.
- Add unit tests
Test the Apex wrapper with representative input payloads. Use System.assert to confirm the script produces the expected output. The DataWeave CLI also lets you test the script locally before deploy.
The current supported version. Targets DataWeave 2.x syntax. All new resources should declare this version.
Synchronous calls run within the calling transaction. No separate governor limits, but the script's CPU and heap consume from the Apex limits.
DataWeave Resources support package namespacing. Reference scripts from managed packages as namespace__ScriptName.
Conventional location is force-app/main/default/dw/. The metadata API accepts other paths if force-meta declares them, but tooling expects the conventional layout.
- DataWeave Resources are not editable from the Setup UI. The list page shows what is deployed but offers no edit button. All changes are source-controlled and redeployed.
- Heavy DataWeave scripts on large payloads burn Apex CPU. There is no separate governor envelope. Test with production-sized inputs before relying on it in a real-time path.
- Errors in DataWeave throw Dataweave.ScriptException, not standard System.JSONException. Catch the right type or the calling code will surface unexpected error shapes.
- DataWeave is generally available since Winter '23. Older orgs may need to enable it under Setup, then DataWeave Resources, then Enable DataWeave.