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
teena jacobteena jacob 

Can we call a trigger when we click a custom button on a VF page.

Hi,

    I have written a trigger .I want this trigger to be executed when clicked on a custom button in a VF page. Can anyone help me out with this?
Thanks.
Best Answer chosen by teena jacob
GauravGargGauravGarg
Hi Teena,

Trigger bascially run's on Object event i.e. Insert, Update, Delete.  If you want to run a specific block of code on button click, follow below steps:
  1. Create apex class
  2. write method in apex class with specific block of code
  3. Link apex class with VF page as extension / controller. 
  4. Call apex method on button click. 

Thanks,

Gaurav
Skype: gaurav62990
support: gauravgarg.nmims@gmail.com

All Answers

Jainam ContractorJainam Contractor
Hi Teena,

You are getting confused with the Trigger functionaity. Trigger is a piece of code that will be executed when there is any DML Operation on the record based on the Trigger event you chose.

Say for eg: When you click a button VF page, if that button does any DML operation on the SObject record then the trigger on that SObject will get executed. Means, if your Custom Button on VF page updates, inserts or deletes an Account record then if there is a trigger on the Account object defined for any of the above DML operation, then that trigger will get executed. You dont have to explicitly call trigger anywhere.

Please let me know if you need more assistance.

Thanks,
Jainam Contractor,
Salesforce Consultant
Varasi LLC
www.varasi.com 
GauravGargGauravGarg
Hi Teena,

Trigger bascially run's on Object event i.e. Insert, Update, Delete.  If you want to run a specific block of code on button click, follow below steps:
  1. Create apex class
  2. write method in apex class with specific block of code
  3. Link apex class with VF page as extension / controller. 
  4. Call apex method on button click. 

Thanks,

Gaurav
Skype: gaurav62990
support: gauravgarg.nmims@gmail.com

This was selected as the best answer