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

Custom button calling a trigger

I have a scenario where i'm auto populating the values using javascript button (which further invokes an apex class). Now the real problem is when these fields are updated, it is invoking a trigger due to update operation.  Is there a way to prevent this?  In another words, Is there a way to bypass the trigger if the button is clicked?
Agustina GarciaAgustina Garcia
I'm afraid that you cannot prevent to call a trigger if there is a dml. Even if you have not created any trigger at all, Salesforce call its own before/after dml by default, as part of the execution ( But obviously it would not do anything if you do not define any action there.

What you can do is create a context variable in order ot know that the action comes from the button and then, do not go inside the update trigger code. Something like:
    //execute update trigger operations
//otherwise I do not do anything

Also, remind you that JS buttons are not supported in Lightning Experience so be sure there is no other way to solve this problem in Classic UI that also works in LEX.