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
Rajesh SFDCRajesh SFDC 

how to add a button page to enable/disable the apex trigger ?

Here,my requirements, i am created one apex trigger. i want to cal those apex trigger to custom button for Enable or disbale is it possiable ?
PratikPratik (Salesforce Developers) 
Hi Rajesh,

Hers is the approach that you can go for:
1. Create a checkbox on the object on which you are writing trigger.
2. Give a condition in trigger that it will be fired only when the checkbox is Checked (true)
3. Create a button which will check or uncheck the value of that Checkbox.

You can refer to this for button:
https://success.salesforce.com/answers?id=90630000000gpNsAAI

Thanksm
Pratik

P.S. If this answers you question, please mark it as "Best Answer" so it will help other community members too.
Rajesh SFDCRajesh SFDC
Hi Pratik,
            Thank you for your reply, when clickon button, trigger it will fire.After that disable the apex trigger. i need a two buttons name as Enable and Disable.is it possiable ? 
PratikPratik (Salesforce Developers) 
Hi Rajesh,

You should change the value on the button click. You can have 2 buttons Enable & Disable whose value should drive the trigger. 

Thanks,
Pratik
Rajesh SFDCRajesh SFDC
But every time i dont want to click on Enable buttons, suppose once enable the buttons, it will work all times, here i am created the new records means i want to click on enable button right.
PratikPratik (Salesforce Developers) 
Hi Rajesh,

The button will be placed on Record so it will controll that record.
So if you go through my first comment above,
Keep only one button which should be say "Disable", this button will Check (true) the Checkbox. (keep the default value of Checkbox as Unchecked)
Write a trigger which will check for Checkbox, if it's unchecked trigger should run else it should not). So your button "Disable" will check (true) the checkbox which will in turn not run the trigger.
Hope it will help!

Thanks,
Pratik
Rajesh SFDCRajesh SFDC
Hi Pratik,
       
Thanks for your support, My questions is if i click on  disable button my trigger will not fire whenever record is create or not , if i click on enable button once my trigger will fire at evertime a record is create or update and i dont want to enable or disable at everytime record is create or update.