Jeet
Jeet

Reputation: 321

Error handling in Mule Salesforce Batch

I am trying to load a set of Accounts into Salesforce from a CSV file. I have configured the usual Datamapper, Upsert SFDC Step with Batch Commit and a Batch Step that handles only failures (logs for now). My OnComplete has a simple Logger. I have intentionally created CSV with bad data. I have an external ID in the CSV.

My requirement is to process failed records differently based on the failure status. If it failed due to Bad Data, I would like to stop processing the record. If it failed due to Parent Key not found, I would like to retry. My batch Step to process Only errors, doesn't know why it failed. Somehow, I would like to pass the "Why it failed" to my failure processing bacth step.

I'm sure this is a simple pattern, but am unable to figure out how to correlate :(

Upvotes: 0

Views: 1814

Answers (1)

Star
Star

Reputation: 1503

In <batch:step name="Handle Failure" accept-policy="ONLY_FAILURES"/> you can use #[getStepException()] MEL to get the exception Map.Later than you can use choice component based on the exception you wants to handle the logic. Refer:http://blogs.mulesoft.com/dev/mule-dev/handle-errors-batch-job/

Make sure using <batch:job name="BatchFlow" max-failed-records="-1">, max failed record set to -1, so that flow wont be stopped and if failure happens in any record it will pass it to 'only failure' flow.

  <batch:job name="BatchFlow" max-failed-records="-1">
    <batch:process-records>
        <batch:step name="Batch_Step">
        <!-- Success flow... -->

        </batch:step>
        <batch:step name="Handle Failure" accept-policy="ONLY_FAILURES">
            <logger message="Details:#[getStepException()]" level="INFO" doc:name="Logger"/>
           <!--  other logic  -->

        </batch:step>
    </batch:process-records>
</batch:job>

Upvotes: 2

Related Questions