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
AutobatAutobat 

Scheduler Runs Batch, Batch Runs Update, Update doesnt run Workflow Email?

Hey Guys,

 

Here is an interesting one for you.  I have dug through the documentation and cant find a limitation documented anywhere so I'm now thinking its an undocumented feature???

 

 

Apex Scheduler triggers a batch that simply runs an update over a subset of Leads at 5am each morning.  The batch runs perfectly and updates a number of complex status fields as defined by some related objects.  Its really just a workaround for not being able to use a master detail.  Where the problem lies is that there are a number of small conditions that should fire an email to the Lead via workflow, all of these are configured and working if i perform an update through the front end, however, when the batch runs no emails are produced.

 

So, enforced limitation, undocumented feature or bug?

 

Cheers,

 

Rick_NookIndRick_NookInd

I've run the gambit of Workflow problems, but as far as I've seen Apex code DML always triggers workflows.

 

If this is true, this likely is related to the "feature" that Workflows can't trigger other Workflows.  Are you doing "Field Update" in Workflows?  If so, unfortunately thats not a best practice.

 

Can you narrow things down a little?  Is it using the scheduler, the batch, or the combination that is causing this?  Have to verified your theory with a token example that you could post?

 

AutobatAutobat

I'm planning on getting some time towards the end of the week to package up something with minimal logic that replicates the problem, will keep you posted.

 

With some more investigation the problem thickens!

 

From what I have found, not only are the emails not sent but the workflows that should action these events are being marked as processed and so they are never re-evaluated even with a manual UI save.

 

forecast_is_cloudyforecast_is_cloudy

Any DML updates made during a Batch Apex run should definately fire any applicable workflows. I suspect your problem might be with the update logic itself (i.e. its somehow not meeting the workflow rule entry criteria and the email is therefore not getting sent) and not with Batch Apex. I'm definately curious to see the code though and maybe then we can analyze and debug the issue further.