How can I skip trigger execution?

201    Asked by DavidEdmunds in Salesforce , Asked on May 1, 2023

 I have a requirement, wherein I have to skip the execution of trigger on Task after update operation on Task from Case. On update of case fields, I am performing an update operation on Task Object. This fires Task triggers and LastModified by gets changed for all the Task records which are related to Case Object.

My intent is to skip the execution of TaskTriggerHandler method, only for this particular update operation when it happens on the case.

Answered by Darsh K

You can implement that logic by yourself. You can write an UtilClass to check if you execute or not the skip Trigger Logic

public class ByPassUtils { public static Map triggerNameBypassed = new Map(); public static void ByPass(String triggerName){ triggerNameBypassed.put(triggerName,true); } public static void UndoByPass(String triggerName){ triggerNameBypassed.put(triggerName,false); } public static Boolean isByPassed(String triggerName){ return triggerNameBypassed.hasKey(triggerName) && triggerNameBypassed.get(triggerName); } }
logic when you want to bypass (maybe in the case trigger for your example)
ByPassUtils.ByPass('TaskAfterUpdate');
in your trigger code (in your case TaskAfterUpdate)
if(!ByPassUtils.isByPassed('TaskAfterUpdate')){ // your logic here }


Your Answer

Interviews

Parent Categories