I’m clutching at straws here a little, but has anyone ever come across a situation where a Batch Apex routine creates duplicate records, possibly as a result of the
execute method running more than once for the same batch of records?
I’m having a sporadic issue where it appears that a batch routine is creating duplicate records, here are the particulars:
- Batch size of 1 (there are good reasons for that)
- Job runs daily every 15 mins between the hours 8am &
6pm (00’s of records processed)
- Job runs once at midnight for monthly load (000’s of records processed)
- Issue only occurs in the midnight job
- Issue has only occurred twice in the last 18 months, with no apparent pattern
- Safeguards are in place to ensure only one job can run at any one given time (ironically, to prevent duplicate processing)
My code pulls a list of unprocessed records (in the
start method), then processes them one at a time in the
execute method. After each record is processed, it is marked as processed so not processed again.
Any ideas anyone?
Thank you for visiting the Q&A section on Magenaut. Please note that all the answers may not help you solve the issue immediately. So please treat them as advisements. If you found the post helpful (or not), leave a comment & I’ll get back to you as soon as possible.
Salesforce confirmed that this was a bug and a fix is scheduled for release next week.
On mobile so sorry for brevity/typos
Without seeing process itself –
Do you have a unique id on these records you are inserting, or could you use an upsert instead, where key is a unique, case sensitive external id ?
If your insert process used database.insert(data,false) to allow partial success and you had a unique id on each record then you’d be able to log the specific DML failures at time of duplication being prevented, which in turn may help you get to the bottom of the problem, or allow you to do some post insert attempt processing to correct the issue on the fly.
Anyway – just suggestions. Good luck with it!
PS – could there be any validation rules preventing a record from having the processed field updated after you have processed it ?…
All methods was sourced from stackoverflow.com or stackexchange.com, is licensed under cc by-sa 2.5, cc by-sa 3.0 and cc by-sa 4.0