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
sparkysparky 

trigger batching off of time-based workflow

I've set up a situation where:
* changing a field triggers a time-based WF rule, which after an hour
* changes another field on the same object, which
* triggers an apex trigger, which
* changes yet another field

This works fine in general, for small record sets.

However, I just tested it in bulk (by making that first field update to a bunch of records at once), and it failed governor limits (too many DML rows).  I didn't expect this, because as far as we the developers can tell, each record is put on the time-workflow queue separately.  However, it appears that since I triggered the time WF at the same time for all the records, they all came off the queue at the same time and were batched for trigger processing.

Specifcally, I tried this operation w/ 380 records.  It looks like it did one batch of 200 and one batch of 180.  So exactly what you'd expect if there was no time WF involved.

But the weird part is: it seems to have batched the records, but not scaled the governor limits to account for it.  So in my batch of 200, I got an error message saying: too many DML rows 201.  But for a trigger operating on 200 records, the limit for DML rows should be 20k.  And I got 200 separate email error messages delivered. So it seems to be treating it as partly a batch, but partly 200 separate operations.

Can someone help with this?  Is this how it's meant to work?

Thanks much!
Best Answer chosen by Admin (Salesforce Developers) 
sparkysparky

FYI to anyone following this: couldn't wait any more for an answer from SF, so went ahead and did some testing.

 

Looks to me like this has been fixed.  It still batched off of the time-based WF, but this time the gov limits seem to have scaled appropriately.

All Answers

Paul - SalesbriPaul - Salesbri
Hi Sparky

We are having the same issue when trying to batch process Invoice records, did you ever come up with a solution for this?

Please do let me know.

Thanks
sparkysparky
Bump.

Nope, nothing yet.

Can anyone at SF address this?
gogz_sfdcgogz_sfdc
Hi,

I work for Salesforce support as part of the developer support group. I've just come across this issue thanks to a customer logging it. I'm going to escalate this internally and will update this thread when I have an answer, in the meantime if someone has come up with a solution/workaround to this issue let me know.

Thanks

Eoin
Always ThinkinAlways Thinkin
Hi Sparky,
Can't explain the crazy behavior you're seeing but could you circumvent it by running the method asynchronously?

Luke C
MelliottMelliott
We're running into this as well.  Our apex code that the workflow is triggering does not allow batches because it is very large and hitting the governor limits if it runs on batches.  Our issue is sometimes, it deploys and sometimes it doesn't.  There is no rhyme or reason and it's driving me and my users nuts.  Any help would be appreciated.
PaulATPimptastiPaulATPimptasti

Hi Melissa,

 

I haven't had time to try this out myself, but this link from Appirio seems to beable to get round the issue.

 

Using Client Side Looping

 

It won't work for all situations, but certainly seems to help solve one of our batching issues.

gogz_sfdcgogz_sfdc

Ok so I got in contact with the Product Manager team about this (sorry for the late reply)

 

This is a bug and it is now logged, I don't have any info on a release date yet 

 

Basically the records are batched for the time based workflow queue but Apex is not runnig in its batched mode. There is no simple workaorund I'm aware of. 

sparkysparky

Hey gogz, or anyone else at SF:

 

Any word on whether this bug ever got addressed, or when it will be addressed?

 

Thanks!

sparkysparky

FYI to anyone following this: couldn't wait any more for an answer from SF, so went ahead and did some testing.

 

Looks to me like this has been fixed.  It still batched off of the time-based WF, but this time the gov limits seem to have scaled appropriately.

This was selected as the best answer