1

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?

2 Answers 2

2

Salesforce confirmed that this was a bug and a fix is scheduled for release next week.

1

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 ?...

4
  • Thanks for your suggestion, i'm almost convinced this is an issue at salesforce end and wondered if anyone else had seen anything similar. No errors are being reported. Jan 16, 2015 at 13:27
  • I would keep debugging :) do you check that the processing field has absolutely, definitely without doubt cross-your-heart been updated after processing? Is the update to processing field DML inside a try catch that might fail silently?.. Jan 16, 2015 at 20:59
  • in a try/catch - if there are errors, I know about them Jan 16, 2015 at 21:23
  • Ok great - so i assume you are successfully updating batch records as processed and inserting new related records which is where duplicates are - Is that correct ? If so, may need to delve into the execute method to explore the logic and list of new records it is eventually inserting as duplicate answer possibly lies there. Again - if you place a unique id on the records being inserted you definitely prevent duplication at insert. Good luck with it. Jan 16, 2015 at 22:31

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .