{"id":2516,"date":"2026-11-04T09:00:00","date_gmt":"2026-11-04T03:30:00","guid":{"rendered":"https:\/\/swapnilzambare.com\/blog\/dataweave-in-apex\/"},"modified":"2026-11-15T22:00:38","modified_gmt":"2026-11-15T16:30:38","slug":"dataweave-in-apex","status":"publish","type":"post","link":"https:\/\/swapnilzambare.com\/blog\/dataweave-in-apex\/","title":{"rendered":"DataWeave in Apex for Data Transformation Explained"},"content":{"rendered":"\n<p class=\"wp-block-paragraph\">DataWeave in Apex lets you turn a CSV, JSON or XML payload into Salesforce records with a short declarative script instead of a parser you write and maintain. The script lives in the org as metadata, and Apex calls it with the payload.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Anyone who has written a CSV parser in Apex knows why this matters. The first version splits on commas, the second handles quoted values, the third handles quotes inside quoted values, and by the fourth you own a hundred lines of code that nobody wants to touch.<\/p>\n\n\n\n<figure class=\"wp-block-image aligncenter size-large\"><a href=\"https:\/\/swapnilzambare.com\/blog\/wp-content\/uploads\/2026\/11\/dataweave-in-apex-diagram-1.png\"><img loading=\"lazy\" decoding=\"async\" width=\"1024\" height=\"640\" src=\"https:\/\/swapnilzambare.com\/blog\/wp-content\/uploads\/2026\/11\/dataweave-in-apex-diagram-1-1024x640.png\" alt=\"DataWeave in Apex diagram showing input, script and sObject output\" class=\"wp-image-2514\" srcset=\"https:\/\/swapnilzambare.com\/blog\/wp-content\/uploads\/2026\/11\/dataweave-in-apex-diagram-1-1024x640.png 1024w, https:\/\/swapnilzambare.com\/blog\/wp-content\/uploads\/2026\/11\/dataweave-in-apex-diagram-1-300x188.png 300w, https:\/\/swapnilzambare.com\/blog\/wp-content\/uploads\/2026\/11\/dataweave-in-apex-diagram-1-768x480.png 768w\" sizes=\"auto, (max-width: 1024px) 100vw, 1024px\" \/><\/a><\/figure>\n\n\n\n<p class=\"wp-block-paragraph\">Caption: The script is metadata, so it deploys and versions like any other component.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">What Is DataWeave in Apex<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">DataWeave in Apex is based on a transformation language from MuleSoft, and Salesforce brought it into the platform as a metadata type. A script is a <code>.dwl<\/code> file with three parts.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>%dw 2.0\ninput records application\/csv\noutput application\/apex\n---\nrecords map (r) -&gt; {\n  Name: r.Title,\n  Fee__c: r.Fee as Number,\n  Is_Online__c: r.Online == 'yes',\n  Start_Date__c: r.Start as Date { format: 'yyyy-MM-dd' }\n} as Object { class: 'Course__c' }<\/code><\/pre>\n\n\n\n<figure class=\"wp-block-table\"><table><thead><tr><th>Part<\/th><th>What it declares<\/th><\/tr><\/thead><tbody><tr><td>The header<\/td><td>The DataWeave version and the inputs<\/td><\/tr><tr><td>The output line<\/td><td>The target format, such as application\/apex<\/td><\/tr><tr><td>The body, after the dashes<\/td><td>The transformation itself<\/td><\/tr><\/tbody><\/table><\/figure>\n\n\n\n<p class=\"wp-block-paragraph\">That <code>as Object { class: 'Course__c' }<\/code> line is the piece people miss. Without it you get a list of maps. With it you get a list of <code>Course__c<\/code> records ready for DML.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">Calling It from Apex<\/h3>\n\n\n\n<pre class=\"wp-block-code\"><code>public with sharing class CourseImporter {\n\n    public static List&lt;Course__c&gt; parse(String csvBody) {\n        DataWeave.Script script = new DataWeaveScriptResource.csvToCourse();\n        DataWeave.Result result = script.execute(\n            new Map&lt;String, Object&gt;{ 'records' =&gt; csvBody }\n        );\n        return (List&lt;Course__c&gt;) result.getValue();\n    }\n}<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">DataWeave in Apex generates an inner class per script, so <code>new DataWeaveScriptResource.csvToCourse()<\/code> gives you a typed handle. The older route, <code>DataWeave.Script.createScript('csvToCourse')<\/code>, still works and takes the name as a string.<\/p>\n\n\n\n<figure class=\"wp-block-table\"><table><thead><tr><th>Member<\/th><th>What it does<\/th><\/tr><\/thead><tbody><tr><td>DataWeaveScriptResource.name<\/td><td>The generated class for one script<\/td><\/tr><tr><td>createScript(name)<\/td><td>Loads a script by name<\/td><\/tr><tr><td>execute(inputs)<\/td><td>Runs it with a map of named inputs<\/td><\/tr><tr><td>Result.getValue()<\/td><td>The output, cast to what the script produced<\/td><\/tr><tr><td>System.DataWeaveScriptException<\/td><td>Thrown when the script fails at runtime<\/td><\/tr><\/tbody><\/table><\/figure>\n\n\n\n<p class=\"wp-block-paragraph\">DataWeave in Apex matches the input map keys to the names declared in the script header. A mismatch there is the most common first error, and the message is not always obvious.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Why DataWeave in Apex Matters<\/h2>\n\n\n\n<figure class=\"wp-block-table\"><table><thead><tr><th>Benefit<\/th><th>What it saves you<\/th><\/tr><\/thead><tbody><tr><td>No parser to write<\/td><td>A hundred lines and its edge cases<\/td><\/tr><tr><td>Type conversion in one line<\/td><td>Per field casting code<\/td><\/tr><tr><td>Three formats from one tool<\/td><td>Separate CSV, JSON and XML handling<\/td><\/tr><tr><td>Metadata, not code<\/td><td>It deploys and versions normally<\/td><\/tr><tr><td>Readable mapping<\/td><td>A field map a reviewer can check<\/td><\/tr><\/tbody><\/table><\/figure>\n\n\n\n<p class=\"wp-block-paragraph\">The readable mapping row is the one business analysts notice. A mapping expressed as fifteen lines of field pairs can be checked by someone who does not write Apex, which is not true of a parser. The post on <a href=\"https:\/\/swapnilzambare.com\/blog\/json-in-apex-serialize-deserialize\/\">JSON in Apex<\/a> covers the native route for comparison.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Going the Other Way<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">DataWeave in Apex also turns records into a payload, which is useful before a callout.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>%dw 2.0\ninput records application\/apex\noutput application\/json\n---\nrecords map (r) -&gt; {\n  courseId: r.Id,\n  title: r.Name,\n  fee: r.Fee__c default 0\n}<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">That <code>default 0<\/code> is a small example of why the syntax is worth learning. Null handling, renaming and nesting all sit inside the mapping rather than in branching Apex.<\/p>\n\n\n\n<figure class=\"wp-block-table\"><table><thead><tr><th>Output format<\/th><th>Common use<\/th><\/tr><\/thead><tbody><tr><td>application\/json<\/td><td>A request body for a callout<\/td><\/tr><tr><td>application\/xml<\/td><td>A legacy SOAP style payload<\/td><\/tr><tr><td>application\/csv<\/td><td>A file for an outside system<\/td><\/tr><tr><td>application\/apex<\/td><td>sObjects or Apex types<\/td><\/tr><\/tbody><\/table><\/figure>\n\n\n\n<h2 class=\"wp-block-heading\">Script Files and Metadata<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">A DataWeave in Apex script is two files, exactly like an Apex class.<\/p>\n\n\n\n<figure class=\"wp-block-table\"><table><thead><tr><th>File<\/th><th>What it is<\/th><\/tr><\/thead><tbody><tr><td>csvToCourse.dwl<\/td><td>The script body<\/td><\/tr><tr><td>csvToCourse.dwl-meta.xml<\/td><td>The metadata, holding the API version<\/td><\/tr><\/tbody><\/table><\/figure>\n\n\n\n<pre class=\"wp-block-code\"><code>&lt;?xml version=\"1.0\" encoding=\"UTF-8\"?&gt;\n&lt;DataWeaveResource xmlns=\"http:\/\/soap.sforce.com\/2006\/04\/metadata\"&gt;\n  &lt;apiVersion&gt;62.0&lt;\/apiVersion&gt;\n  &lt;isGlobal&gt;true&lt;\/isGlobal&gt;\n&lt;\/DataWeaveResource&gt;<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">The API version in that file decides which DataWeave version you get, and the versions differ in available functions. Setting <code>isGlobal<\/code> makes the generated class global, which matters when the script ships in a managed package.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">DataWeave in Apex vs Writing the Parser<\/h2>\n\n\n\n<figure class=\"wp-block-image aligncenter size-large\"><a href=\"https:\/\/swapnilzambare.com\/blog\/wp-content\/uploads\/2026\/11\/dataweave-in-apex-diagram-2.png\"><img loading=\"lazy\" decoding=\"async\" width=\"1024\" height=\"640\" src=\"https:\/\/swapnilzambare.com\/blog\/wp-content\/uploads\/2026\/11\/dataweave-in-apex-diagram-2-1024x640.png\" alt=\"DataWeave in Apex and hand written parsing comparison diagram\" class=\"wp-image-2515\" srcset=\"https:\/\/swapnilzambare.com\/blog\/wp-content\/uploads\/2026\/11\/dataweave-in-apex-diagram-2-1024x640.png 1024w, https:\/\/swapnilzambare.com\/blog\/wp-content\/uploads\/2026\/11\/dataweave-in-apex-diagram-2-300x188.png 300w, https:\/\/swapnilzambare.com\/blog\/wp-content\/uploads\/2026\/11\/dataweave-in-apex-diagram-2-768x480.png 768w\" sizes=\"auto, (max-width: 1024px) 100vw, 1024px\" \/><\/a><\/figure>\n\n\n\n<p class=\"wp-block-paragraph\">Caption: Mapping work goes to the script, and real logic stays in Apex.<\/p>\n\n\n\n<figure class=\"wp-block-table\"><table><thead><tr><th>Task<\/th><th>Pick<\/th><\/tr><\/thead><tbody><tr><td>CSV upload to records<\/td><td>DataWeave script<\/td><\/tr><tr><td>A nested JSON response to sObjects<\/td><td>DataWeave script<\/td><\/tr><tr><td>XML from a legacy system<\/td><td>DataWeave script<\/td><\/tr><tr><td>Business rules on the imported data<\/td><td>Apex<\/td><\/tr><tr><td>Deciding which records to skip<\/td><td>Apex, after the mapping<\/td><\/tr><tr><td>A single flat JSON object<\/td><td>JSON.deserialize in Apex<\/td><\/tr><\/tbody><\/table><\/figure>\n\n\n\n<p class=\"wp-block-paragraph\">That last row is worth saying plainly. For a simple JSON payload matching an Apex class, the native deserialize call is less work than a script. DataWeave in Apex earns its place when the shape has to change.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">A Real DataWeave in Apex Example<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">DataWeave in Apex replaced a parser we had stopped trusting. Bright Path Tutors receives a weekly CSV of course updates from a partner. Columns move, some fees are blank, and dates arrive in two formats.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">The original Apex parser had grown over two years.<\/p>\n\n\n\n<figure class=\"wp-block-table\"><table><thead><tr><th>Problem<\/th><th>What it cost<\/th><\/tr><\/thead><tbody><tr><td>180 lines of parsing code<\/td><td>Nobody wanted to change it<\/td><\/tr><tr><td>Quoted commas in course titles<\/td><td>Three separate bug fixes<\/td><\/tr><tr><td>Blank fee values<\/td><td>A null reference failure each month<\/td><\/tr><tr><td>A new column added by the partner<\/td><td>A deployment every time<\/td><\/tr><\/tbody><\/table><\/figure>\n\n\n\n<p class=\"wp-block-paragraph\">Imports of this size are also candidates for <a href=\"https:\/\/swapnilzambare.com\/blog\/salesforce-bulk-api-2\/\">Bulk API 2.0<\/a> when the file grows, and for <a href=\"https:\/\/swapnilzambare.com\/blog\/batch-apex-start-execute-finish\/\">batch Apex<\/a> when the mapped records need processing in chunks.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">We replaced it with a 14 line script.<\/p>\n\n\n\n<figure class=\"wp-block-table\"><table><thead><tr><th>Measure<\/th><th>Apex parser<\/th><th>DataWeave script<\/th><\/tr><\/thead><tbody><tr><td>Lines to maintain<\/td><td>180<\/td><td>14<\/td><\/tr><tr><td>Who can review a mapping change<\/td><td>A developer<\/td><td>An analyst<\/td><\/tr><tr><td>Bugs from quoting and escaping<\/td><td>3 in two years<\/td><td>0<\/td><\/tr><tr><td>Work to add a column<\/td><td>Code change and tests<\/td><td>One line in the script<\/td><\/tr><\/tbody><\/table><\/figure>\n\n\n\n<p class=\"wp-block-paragraph\">Blank fees were handled by a <code>default 0<\/code> and the two date formats by a single conditional expression. The Apex class shrank to a call and a DML statement.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Limits and Things to Watch<\/h2>\n\n\n\n<ul class=\"wp-block-list\">\n<li>A maximum of 50 scripts per org, so treat them as a shared resource<\/li>\n\n<li>A script body is capped at 100,000 characters<\/li>\n\n<li>Modules and importing other scripts are not supported, so each script is self contained<\/li>\n\n<li>The Java bridge is disabled, and so are functions that reach the environment<\/li>\n\n<li>Blob input needs an explicit encoding before it can be read as a string<\/li>\n\n<li>Apex classes must be on API version 53.0 or later to call these methods<\/li>\n\n<li>XML entity expansion is not supported, as a guard against denial of service attacks<\/li>\n<\/ul>\n\n\n\n<p class=\"wp-block-paragraph\">The 50 script ceiling in DataWeave in Apex is the one to plan around. Write one script per integration rather than one per field mapping variant, and use conditional logic inside the script instead of creating near duplicates.<\/p>\n\n\n\n<figure class=\"wp-block-table\"><table><thead><tr><th>Apex API version<\/th><th>DataWeave version you get<\/th><\/tr><\/thead><tbody><tr><td>61.0 and earlier<\/td><td>DataWeave 2.5<\/td><\/tr><tr><td>62.0<\/td><td>DataWeave 2.8<\/td><\/tr><tr><td>63.0 and later<\/td><td>DataWeave 2.9<\/td><\/tr><\/tbody><\/table><\/figure>\n\n\n\n<h3 class=\"wp-block-heading\">Debugging a Script<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">DataWeave in Apex has a <code>log<\/code> function that writes into the Apex debug log, under the Apex Code category at debug level, as a DataWeave user debug event.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>records map (r) -&gt; {\n  Name: log('title', r.Title)\n}<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">That one function removes most of the guesswork. The interactive DataWeave playground is also worth using, since iterating there is far quicker than deploying a script each time.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Common Mistakes with DataWeave in Apex<\/h2>\n\n\n\n<figure class=\"wp-block-table\"><table><thead><tr><th>Mistake<\/th><th>What you see<\/th><th>Fix<\/th><\/tr><\/thead><tbody><tr><td>Input name does not match the header<\/td><td>A confusing runtime error<\/td><td>Match the map key to the declared input name<\/td><\/tr><tr><td>No class clause on the output<\/td><td>A list of maps, not sObjects<\/td><td>Add the as Object class line<\/td><\/tr><tr><td>No encoding on blob input<\/td><td>A coercion failure<\/td><td>Declare the encoding explicitly<\/td><\/tr><tr><td>One script per variant<\/td><td>The 50 script ceiling<\/td><td>Use conditions inside one script<\/td><\/tr><tr><td>Business rules inside the script<\/td><td>Logic nobody can test properly<\/td><td>Keep rules in Apex<\/td><\/tr><tr><td>No try and catch around execute<\/td><td>An unhandled script exception<\/td><td>Catch DataWeaveScriptException<\/td><\/tr><tr><td>Trusting the partner column order<\/td><td>Silent wrong mapping<\/td><td>Map by column name, not position<\/td><\/tr><\/tbody><\/table><\/figure>\n\n\n\n<h2 class=\"wp-block-heading\">Best Practices for DataWeave in Apex<\/h2>\n\n\n\n<ul class=\"wp-block-list\">\n<li>One script per integration, with conditions rather than near duplicates<\/li>\n\n<li>Map by column name so a reordered file still works<\/li>\n\n<li>Use the default keyword for every field that may arrive blank<\/li>\n\n<li>Keep the script to mapping and leave business rules in Apex<\/li>\n\n<li>Catch the script exception and log the payload shape, not the payload itself<\/li>\n\n<li>Build and test the script in the playground before deploying it<\/li>\n\n<li>Name scripts after the direction, such as csvToCourse and courseToJson<\/li>\n<\/ul>\n\n\n\n<h2 class=\"wp-block-heading\">Most Asked DataWeave in Apex Interview Questions<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>Q1: What is DataWeave in Apex?<\/strong><\/p>\n\n\n\n<p class=\"wp-block-paragraph\">A transformation language available as org metadata, called from Apex to convert and map data.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>Q2: What file extension does a script use?<\/strong><\/p>\n\n\n\n<p class=\"wp-block-paragraph\">A dwl file, with an accompanying meta xml file.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>Q3: What are the three parts of a script?<\/strong><\/p>\n\n\n\n<p class=\"wp-block-paragraph\">The header with inputs, the output declaration, and the body after the dashes.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>Q4: Which formats can it read and write?<\/strong><\/p>\n\n\n\n<p class=\"wp-block-paragraph\">CSV, JSON and XML, as well as the Apex format for sObjects and Apex types.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>Q5: How do you get sObjects out rather than maps?<\/strong><\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Add the class clause to the output object, naming the sObject type.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>Q6: How do you call a script from Apex?<\/strong><\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Through the generated resource class, or by name with createScript, then execute with a map of inputs.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>Q7: What does execute return?<\/strong><\/p>\n\n\n\n<p class=\"wp-block-paragraph\">A Result object, and getValue gives the output to cast.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>Q8: What exception should you catch?<\/strong><\/p>\n\n\n\n<p class=\"wp-block-paragraph\">System.DataWeaveScriptException, which surfaces runtime failures from inside the script.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>Q9: What must match between Apex and the script?<\/strong><\/p>\n\n\n\n<p class=\"wp-block-paragraph\">The input names, since the map keys are matched to the declared inputs.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>Q10: How many scripts can an org hold?<\/strong><\/p>\n\n\n\n<p class=\"wp-block-paragraph\">A maximum of 50.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>Q11: What is the size limit for one script?<\/strong><\/p>\n\n\n\n<p class=\"wp-block-paragraph\">100,000 characters in the body.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>Q12: Can one script import another?<\/strong><\/p>\n\n\n\n<p class=\"wp-block-paragraph\">No. Modules and imports are not supported, so each script is self contained.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>Q13: Is the Java bridge available?<\/strong><\/p>\n\n\n\n<p class=\"wp-block-paragraph\">No. Binding to Java methods is disabled, and so are environment functions.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>Q14: What is needed for blob input?<\/strong><\/p>\n\n\n\n<p class=\"wp-block-paragraph\">An explicit encoding, so the binary can be read as a string.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>Q15: Which API version does Apex need?<\/strong><\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Version 53.0 or later to use these methods.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>Q16: What decides the DataWeave version?<\/strong><\/p>\n\n\n\n<p class=\"wp-block-paragraph\">The API version in the script metadata file.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>Q17: What does isGlobal do?<\/strong><\/p>\n\n\n\n<p class=\"wp-block-paragraph\">It makes the generated resource class global, which matters for managed packages.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>Q18: How do you debug a script?<\/strong><\/p>\n\n\n\n<p class=\"wp-block-paragraph\">With the log function, which appears in the Apex debug log as a DataWeave debug event.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>Q19: Where is the fastest place to iterate on a script?<\/strong><\/p>\n\n\n\n<p class=\"wp-block-paragraph\">The interactive playground, rather than deploying each change.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>Q20: How do you handle a blank numeric column?<\/strong><\/p>\n\n\n\n<p class=\"wp-block-paragraph\">With the default keyword, which gives a value when the input is missing.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>Q21: Why map by column name rather than position?<\/strong><\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Because partners reorder columns, and a positional map then maps the wrong data silently.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>Q22: When is native JSON deserialize the better choice?<\/strong><\/p>\n\n\n\n<p class=\"wp-block-paragraph\">For a flat payload that already matches an Apex class, where no reshaping is needed.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>Q23: Should business rules live in the script?<\/strong><\/p>\n\n\n\n<p class=\"wp-block-paragraph\">No. Keep mapping in the script and rules in Apex, where they can be tested properly.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>Q24: Scenario: the result is a list of maps instead of records. What is missing?<\/strong><\/p>\n\n\n\n<p class=\"wp-block-paragraph\">The class clause on the output object.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>Q25: Scenario: titles containing commas break the import. Does the script handle it?<\/strong><\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Yes. Quoted values are handled by the CSV reader, which is a common Apex parser bug.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>Q26: Scenario: the script fails with an input error. What do you check first?<\/strong><\/p>\n\n\n\n<p class=\"wp-block-paragraph\">That the map key in Apex matches the input name declared in the header.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>Q27: Scenario: you need a 51st script. What now?<\/strong><\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Consolidate near duplicates with conditions, since the ceiling is per org.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>Q28: Does DataWeave heap usage count against the Apex transaction?<\/strong><\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Treat heap as a shared concern and test with a realistic payload size rather than a sample row.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>Q29: What is the one habit that makes scripts maintainable?<\/strong><\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Keep each script to mapping only, name inputs clearly, and test it in the playground first.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Official Resources<\/h2>\n\n\n\n<ul class=\"wp-block-list\">\n<li><a href=\"https:\/\/developer.salesforce.com\/docs\/atlas.en-us.apexcode.meta\/apexcode\/\" target=\"_blank\" rel=\"noopener noreferrer\">Apex Developer Guide<\/a><\/li>\n\n<li><a href=\"https:\/\/docs.mulesoft.com\/dataweave\/latest\/\" target=\"_blank\" rel=\"noopener noreferrer\">DataWeave Reference<\/a><\/li>\n\n<li><a href=\"https:\/\/github.com\/trailheadapps\/apex-recipes\" target=\"_blank\" rel=\"noopener noreferrer\">Apex Recipes<\/a><\/li>\n<\/ul>\n\n\n\n<h2 class=\"wp-block-heading\">What Is Next<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">Next, read <a href=\"https:\/\/swapnilzambare.com\/blog\/salesforce-big-objects\/\">Salesforce Big Objects for Billions of Records Explained<\/a>.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>DataWeave in Apex lets you turn a CSV, JSON or XML payload into Salesforce records with a short declarative script instead of a parser&hellip;<\/p>\n","protected":false},"author":1,"featured_media":2513,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"_swapz_level":"","_swapz_series_part":0,"_swapz_hide_toc":false,"_swapz_hide_featured":false,"_swapz_description":"","footnotes":""},"categories":[246,8,96],"tags":[68,98,81],"swapz_series":[],"class_list":["post-2516","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-integration-apis","category-salesforce","category-salesforce-developer","tag-advanced","tag-apex","tag-integration"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v28.9 - https:\/\/yoast.com\/product\/yoast-seo-wordpress\/ -->\n<title>DataWeave in Apex for Data Transformation<\/title>\n<meta name=\"description\" content=\"DataWeave in Apex turns CSV, JSON and XML into sObjects with a short script instead of parsing code. Learn the setup, the Apex call and the real limits.\" \/>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/swapnilzambare.com\/blog\/dataweave-in-apex\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"DataWeave in Apex for Data Transformation\" \/>\n<meta property=\"og:description\" content=\"DataWeave in Apex turns CSV, JSON and XML into sObjects with a short script instead of parsing code. Learn the setup, the Apex call and the real limits.\" \/>\n<meta property=\"og:url\" content=\"https:\/\/swapnilzambare.com\/blog\/dataweave-in-apex\/\" \/>\n<meta property=\"og:site_name\" content=\"Swapnil Zambare - Blog\" \/>\n<meta property=\"article:published_time\" content=\"2026-11-04T03:30:00+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2026-11-15T16:30:38+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/swapnilzambare.com\/blog\/wp-content\/uploads\/2026\/11\/dataweave-in-apex-featured.png\" \/>\n\t<meta property=\"og:image:width\" content=\"2400\" \/>\n\t<meta property=\"og:image:height\" content=\"1260\" \/>\n\t<meta property=\"og:image:type\" content=\"image\/png\" \/>\n<meta name=\"author\" content=\"Swapnil Zambare\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"Swapnil Zambare\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"10 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\\\/\\\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\\\/\\\/swapnilzambare.com\\\/blog\\\/dataweave-in-apex\\\/#article\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/swapnilzambare.com\\\/blog\\\/dataweave-in-apex\\\/\"},\"author\":{\"name\":\"Swapnil Zambare\",\"@id\":\"https:\\\/\\\/swapnilzambare.com\\\/blog\\\/#\\\/schema\\\/person\\\/10b09224c8bcc562716e86789427592a\"},\"headline\":\"DataWeave in Apex for Data Transformation Explained\",\"datePublished\":\"2026-11-04T03:30:00+00:00\",\"dateModified\":\"2026-11-15T16:30:38+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\\\/\\\/swapnilzambare.com\\\/blog\\\/dataweave-in-apex\\\/\"},\"wordCount\":1889,\"publisher\":{\"@id\":\"https:\\\/\\\/swapnilzambare.com\\\/blog\\\/#organization\"},\"image\":{\"@id\":\"https:\\\/\\\/swapnilzambare.com\\\/blog\\\/dataweave-in-apex\\\/#primaryimage\"},\"thumbnailUrl\":\"https:\\\/\\\/swapnilzambare.com\\\/blog\\\/wp-content\\\/uploads\\\/2026\\\/11\\\/dataweave-in-apex-featured.png\",\"keywords\":[\"Advanced\",\"Apex\",\"Integration\"],\"articleSection\":[\"Integration and APIs\",\"Salesforce\",\"Salesforce Developer\"],\"inLanguage\":\"en-US\"},{\"@type\":\"WebPage\",\"@id\":\"https:\\\/\\\/swapnilzambare.com\\\/blog\\\/dataweave-in-apex\\\/\",\"url\":\"https:\\\/\\\/swapnilzambare.com\\\/blog\\\/dataweave-in-apex\\\/\",\"name\":\"DataWeave in Apex for Data Transformation\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/swapnilzambare.com\\\/blog\\\/#website\"},\"primaryImageOfPage\":{\"@id\":\"https:\\\/\\\/swapnilzambare.com\\\/blog\\\/dataweave-in-apex\\\/#primaryimage\"},\"image\":{\"@id\":\"https:\\\/\\\/swapnilzambare.com\\\/blog\\\/dataweave-in-apex\\\/#primaryimage\"},\"thumbnailUrl\":\"https:\\\/\\\/swapnilzambare.com\\\/blog\\\/wp-content\\\/uploads\\\/2026\\\/11\\\/dataweave-in-apex-featured.png\",\"datePublished\":\"2026-11-04T03:30:00+00:00\",\"dateModified\":\"2026-11-15T16:30:38+00:00\",\"description\":\"DataWeave in Apex turns CSV, JSON and XML into sObjects with a short script instead of parsing code. Learn the setup, the Apex call and the real limits.\",\"breadcrumb\":{\"@id\":\"https:\\\/\\\/swapnilzambare.com\\\/blog\\\/dataweave-in-apex\\\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\\\/\\\/swapnilzambare.com\\\/blog\\\/dataweave-in-apex\\\/\"]}]},{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\\\/\\\/swapnilzambare.com\\\/blog\\\/dataweave-in-apex\\\/#primaryimage\",\"url\":\"https:\\\/\\\/swapnilzambare.com\\\/blog\\\/wp-content\\\/uploads\\\/2026\\\/11\\\/dataweave-in-apex-featured.png\",\"contentUrl\":\"https:\\\/\\\/swapnilzambare.com\\\/blog\\\/wp-content\\\/uploads\\\/2026\\\/11\\\/dataweave-in-apex-featured.png\",\"width\":2400,\"height\":1260,\"caption\":\"DataWeave in Apex featured image showing a CSV file turning into Salesforce records\"},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\\\/\\\/swapnilzambare.com\\\/blog\\\/dataweave-in-apex\\\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\\\/\\\/swapnilzambare.com\\\/blog\\\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"DataWeave in Apex for Data Transformation Explained\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\\\/\\\/swapnilzambare.com\\\/blog\\\/#website\",\"url\":\"https:\\\/\\\/swapnilzambare.com\\\/blog\\\/\",\"name\":\"Swapnil Zambare - Blog\",\"description\":\"Salesforce &amp; Tech Guides\",\"publisher\":{\"@id\":\"https:\\\/\\\/swapnilzambare.com\\\/blog\\\/#organization\"},\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\\\/\\\/swapnilzambare.com\\\/blog\\\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"en-US\"},{\"@type\":\"Organization\",\"@id\":\"https:\\\/\\\/swapnilzambare.com\\\/blog\\\/#organization\",\"name\":\"Swapnil Zambare - Blog\",\"url\":\"https:\\\/\\\/swapnilzambare.com\\\/blog\\\/\",\"logo\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\\\/\\\/swapnilzambare.com\\\/blog\\\/#\\\/schema\\\/logo\\\/image\\\/\",\"url\":\"https:\\\/\\\/swapnilzambare.com\\\/blog\\\/wp-content\\\/uploads\\\/2026\\\/09\\\/site-icon-512.png\",\"contentUrl\":\"https:\\\/\\\/swapnilzambare.com\\\/blog\\\/wp-content\\\/uploads\\\/2026\\\/09\\\/site-icon-512.png\",\"width\":512,\"height\":512,\"caption\":\"Swapnil Zambare - Blog\"},\"image\":{\"@id\":\"https:\\\/\\\/swapnilzambare.com\\\/blog\\\/#\\\/schema\\\/logo\\\/image\\\/\"},\"sameAs\":[\"https:\\\/\\\/www.linkedin.com\\\/in\\\/theSwapnilZambare\"]},{\"@type\":\"Person\",\"@id\":\"https:\\\/\\\/swapnilzambare.com\\\/blog\\\/#\\\/schema\\\/person\\\/10b09224c8bcc562716e86789427592a\",\"name\":\"Swapnil Zambare\",\"sameAs\":[\"https:\\\/\\\/swapnilzambare.com\\\/blog\"],\"url\":\"https:\\\/\\\/swapnilzambare.com\\\/blog\\\/author\\\/swapnil-zambare\\\/\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"DataWeave in Apex for Data Transformation","description":"DataWeave in Apex turns CSV, JSON and XML into sObjects with a short script instead of parsing code. Learn the setup, the Apex call and the real limits.","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/swapnilzambare.com\/blog\/dataweave-in-apex\/","og_locale":"en_US","og_type":"article","og_title":"DataWeave in Apex for Data Transformation","og_description":"DataWeave in Apex turns CSV, JSON and XML into sObjects with a short script instead of parsing code. Learn the setup, the Apex call and the real limits.","og_url":"https:\/\/swapnilzambare.com\/blog\/dataweave-in-apex\/","og_site_name":"Swapnil Zambare - Blog","article_published_time":"2026-11-04T03:30:00+00:00","article_modified_time":"2026-11-15T16:30:38+00:00","og_image":[{"width":2400,"height":1260,"url":"https:\/\/swapnilzambare.com\/blog\/wp-content\/uploads\/2026\/11\/dataweave-in-apex-featured.png","type":"image\/png"}],"author":"Swapnil Zambare","twitter_card":"summary_large_image","twitter_misc":{"Written by":"Swapnil Zambare","Est. reading time":"10 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/swapnilzambare.com\/blog\/dataweave-in-apex\/#article","isPartOf":{"@id":"https:\/\/swapnilzambare.com\/blog\/dataweave-in-apex\/"},"author":{"name":"Swapnil Zambare","@id":"https:\/\/swapnilzambare.com\/blog\/#\/schema\/person\/10b09224c8bcc562716e86789427592a"},"headline":"DataWeave in Apex for Data Transformation Explained","datePublished":"2026-11-04T03:30:00+00:00","dateModified":"2026-11-15T16:30:38+00:00","mainEntityOfPage":{"@id":"https:\/\/swapnilzambare.com\/blog\/dataweave-in-apex\/"},"wordCount":1889,"publisher":{"@id":"https:\/\/swapnilzambare.com\/blog\/#organization"},"image":{"@id":"https:\/\/swapnilzambare.com\/blog\/dataweave-in-apex\/#primaryimage"},"thumbnailUrl":"https:\/\/swapnilzambare.com\/blog\/wp-content\/uploads\/2026\/11\/dataweave-in-apex-featured.png","keywords":["Advanced","Apex","Integration"],"articleSection":["Integration and APIs","Salesforce","Salesforce Developer"],"inLanguage":"en-US"},{"@type":"WebPage","@id":"https:\/\/swapnilzambare.com\/blog\/dataweave-in-apex\/","url":"https:\/\/swapnilzambare.com\/blog\/dataweave-in-apex\/","name":"DataWeave in Apex for Data Transformation","isPartOf":{"@id":"https:\/\/swapnilzambare.com\/blog\/#website"},"primaryImageOfPage":{"@id":"https:\/\/swapnilzambare.com\/blog\/dataweave-in-apex\/#primaryimage"},"image":{"@id":"https:\/\/swapnilzambare.com\/blog\/dataweave-in-apex\/#primaryimage"},"thumbnailUrl":"https:\/\/swapnilzambare.com\/blog\/wp-content\/uploads\/2026\/11\/dataweave-in-apex-featured.png","datePublished":"2026-11-04T03:30:00+00:00","dateModified":"2026-11-15T16:30:38+00:00","description":"DataWeave in Apex turns CSV, JSON and XML into sObjects with a short script instead of parsing code. Learn the setup, the Apex call and the real limits.","breadcrumb":{"@id":"https:\/\/swapnilzambare.com\/blog\/dataweave-in-apex\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/swapnilzambare.com\/blog\/dataweave-in-apex\/"]}]},{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/swapnilzambare.com\/blog\/dataweave-in-apex\/#primaryimage","url":"https:\/\/swapnilzambare.com\/blog\/wp-content\/uploads\/2026\/11\/dataweave-in-apex-featured.png","contentUrl":"https:\/\/swapnilzambare.com\/blog\/wp-content\/uploads\/2026\/11\/dataweave-in-apex-featured.png","width":2400,"height":1260,"caption":"DataWeave in Apex featured image showing a CSV file turning into Salesforce records"},{"@type":"BreadcrumbList","@id":"https:\/\/swapnilzambare.com\/blog\/dataweave-in-apex\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/swapnilzambare.com\/blog\/"},{"@type":"ListItem","position":2,"name":"DataWeave in Apex for Data Transformation Explained"}]},{"@type":"WebSite","@id":"https:\/\/swapnilzambare.com\/blog\/#website","url":"https:\/\/swapnilzambare.com\/blog\/","name":"Swapnil Zambare - Blog","description":"Salesforce &amp; Tech Guides","publisher":{"@id":"https:\/\/swapnilzambare.com\/blog\/#organization"},"potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/swapnilzambare.com\/blog\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":"Organization","@id":"https:\/\/swapnilzambare.com\/blog\/#organization","name":"Swapnil Zambare - Blog","url":"https:\/\/swapnilzambare.com\/blog\/","logo":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/swapnilzambare.com\/blog\/#\/schema\/logo\/image\/","url":"https:\/\/swapnilzambare.com\/blog\/wp-content\/uploads\/2026\/09\/site-icon-512.png","contentUrl":"https:\/\/swapnilzambare.com\/blog\/wp-content\/uploads\/2026\/09\/site-icon-512.png","width":512,"height":512,"caption":"Swapnil Zambare - Blog"},"image":{"@id":"https:\/\/swapnilzambare.com\/blog\/#\/schema\/logo\/image\/"},"sameAs":["https:\/\/www.linkedin.com\/in\/theSwapnilZambare"]},{"@type":"Person","@id":"https:\/\/swapnilzambare.com\/blog\/#\/schema\/person\/10b09224c8bcc562716e86789427592a","name":"Swapnil Zambare","sameAs":["https:\/\/swapnilzambare.com\/blog"],"url":"https:\/\/swapnilzambare.com\/blog\/author\/swapnil-zambare\/"}]}},"_links":{"self":[{"href":"https:\/\/swapnilzambare.com\/blog\/wp-json\/wp\/v2\/posts\/2516","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/swapnilzambare.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/swapnilzambare.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/swapnilzambare.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/swapnilzambare.com\/blog\/wp-json\/wp\/v2\/comments?post=2516"}],"version-history":[{"count":2,"href":"https:\/\/swapnilzambare.com\/blog\/wp-json\/wp\/v2\/posts\/2516\/revisions"}],"predecessor-version":[{"id":3406,"href":"https:\/\/swapnilzambare.com\/blog\/wp-json\/wp\/v2\/posts\/2516\/revisions\/3406"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/swapnilzambare.com\/blog\/wp-json\/wp\/v2\/media\/2513"}],"wp:attachment":[{"href":"https:\/\/swapnilzambare.com\/blog\/wp-json\/wp\/v2\/media?parent=2516"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/swapnilzambare.com\/blog\/wp-json\/wp\/v2\/categories?post=2516"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/swapnilzambare.com\/blog\/wp-json\/wp\/v2\/tags?post=2516"},{"taxonomy":"swapz_series","embeddable":true,"href":"https:\/\/swapnilzambare.com\/blog\/wp-json\/wp\/v2\/swapz_series?post=2516"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}