Skip the execution of trigger

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, 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. Is it possible, if yes, please let me know....

Replay

When you are updating a particular field on case you update a particular field on task which fires another trigger on Task object to update the last modified by.

You can put condition on particular field.

If(Case.someFieldValue == 'someValue'){

//Then only update the task field.

}

You can implement that logic by yourself.

You can write an UtilClass to check if you execute or not the Trigger Logic

public class ByPassUtils {

public static Map<String,Boolean> triggerNameBypassed = new Map<String,Boolean>();

public void Static ByPass(String triggerName){
    triggerNameBypassed.put(triggerName,true);
}

public void Static UndoByPass(String triggerName){
    triggerNameBypassed.put(triggerName,false);
}

public Boolean Static 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
}

There an easy practical way to do something like this

In your Task trigger add something like this

trigger TaskTrigger on Task (..all your before/afters) {

public static isComingFromCase = false;

  public void MyTriggerMethod(...your params) {
    if (isCallingFromCase) {
      return;
    }

    ...rest of your code
  }

}

Then, on whatever method you want to skip the triggers you can do

...code

TaskTrigger.isComingFromCase = true;

...more code

If you set that variable to true before you perform the update that kicks off the Task Trigger then the methods for which you added the if statement won't be executed.

Follow the steps

  • create the checkbox on the task object as isUpdatedFromCaseTrigger
  • When you update the task after the case being updated then make this boolean as true.
  • Then the task trigger will fire, here you will get all the task records updated in this context.
  • Check for the isUpdatedFromCaseTrigger equals to true. If true then don't call the TaskTriggerHandler method.

let me know if you need anything.

Category: apex Time: 2016-07-28 Views: 4
Tags: trigger apex

Related post

iOS development

Android development

Python development

JAVA development

Development language

PHP development

Ruby development

search

Front-end development

Database

development tools

Open Platform

Javascript development

.NET development

cloud computing

server

Copyright (C) avrocks.com, All Rights Reserved.

processed in 0.132 (s). 12 q(s)