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
Vidya DVidya D 

System.Isbatch()

I would like to know which all operation it is guarenteed that System.Isbatch() will be true. 

Data inserted from dataloader or other data migration tools / third party software.
Batch Apex?
Any other API?


pconpcon
It is only if you are using the Apex Batchable context.  It is not if you are loading multiple records via something like the dataloader.
Vidya DVidya D
Thanks. Is there any other flag/field  that can provide indication - data is coming through batch upload? - like Dataloader? Or only option to use custom field pattern to indicate data is coming from batch upload.
 
pconpcon
The only other way is to set a variable in your trigger that looks at the amount of data coming in.  This pattern of classifying your triggers [1] has a isBulk variable that can be used if certian code needs to be bypassed with doing bulk data operations.

Are you experiancing any particular problems with bulk data uploading?

[1] http://blog.deadlypenguin.com/blog/2012/02/13/classifying-triggers-in-salesforce/
Manish Pal 17Manish Pal 17
Hi @pcon I just want to know why we use this System.IsBatch()? 
 
we are using it in code not written by me but I need to make few changes.
if(trigger.isAfter){
           
                    
                    if(!System.isFuture() && !System.isBatch())  {  
                        <className>.<methodName>(trigger.new,trigger.oldmap);

                    }
}

 
pconpcon
I'm assuming that they have some different logic inside the method name that only works if the code is not running in a Batch or Future context.  Without knowing what is inside the method I can't say why it was written to not handle apex batchable.  Whoever wrote that could also have confused isBatch for a method that says if data is being manipulated in bulk.