function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion

How to handle DML Exception during batch Apex?



I wrote a batch Apex job that updates contact records (200 records/batch) by doing a lookup to another table. For the most part, all looks good until a DML Exception occurs. When this happens, none of the records on that batch get updated as expected. My question is: what's the best way to handle this? Can I have a try and catch statement and when the DML Exception is caught, reprocesses all the records within that batch minus the record/records that caused the DML Exception?


Any pointers will be appreciated.


Thanks in advance.


Anyone? :-(