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
FippyFippy 

How do I know if a trigger is within a batch or single context?

Hello all,

 

I have a trigger (case before update) in which I want to do different things depending upon whether the trigger occurs in a batch or single context. (This is to get around a problem I have with a @future method being called from within batch mode)

 

Is there a way to tell if the context is in batch mode? I haven't found anything about this in the docs or forums.

 

Thanks for any help,

Graeme

 

stcforcestcforce

would the size of the trigger.new varaible be an indication? This depends on your usage.

bob_buzzardbob_buzzard

I'm not aware of any way to determine that context via the system, so you'd have to manage it yourself.

 

I think you should be able to achieve this with a class that contains a public static property that defaults to false.  Then in your batch execute method set that property to true, and your trigger can interrogate it.  Each transaction (which equates to each invocation of your execute method) will get its own instance of that static property so there won't be any cross transaction retention of its state.  

FippyFippy

I think I found the solution to my own question. :)

 

system.isBatch()

 

See: http://developer.force.com/releases/release/Winter12/New+System+Methods

 

Graeme