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
Maverick123Maverick123 

By pass an DML activity

Hello All,

 

I have a situation here, where i would like to by pass/avoid a DML acitivity and proceed ahead with further code.

 

My Batch class evokes a trigger on a object, which tries to upsert some related object on it, but in fact there is simply no need and because an issue with that upsert my rest of the code hangs up.

 

Is there a way to avoid it....i have tried to put the upsert in try catch block, but it doesnt help....

try{

upsert x;

}catch(exception e){}

 

Please help....

 

Thanks,

Maverick

Damien_Damien_

Have a static boolean sitting somewhere in another class

 

public static boolean isBypass = false;

 

----------------

 

In your batch do 

 

ClassName.isBypass = true;

 

---------------

 

In your trigger, have your first line be something like:

 

 

if (ClassName.isBypass)

  return;