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
sfdev1sfdev1 

Link Visualforce Button to an Apex code class

Is it possible to link the action of a button submit action to a Apex class?
 
Thanks
 

Stephen
Best Answer chosen by Admin (Salesforce Developers) 
XactiumBenXactiumBen
I think it is possible to do this, however you will need to have a function in your controller which is called by your button.  This function can then call the Apex Class function.

Example Code:

Visualforce Page:
Code:
<apex:commandButton action="{!myAction}" value="Clicky" />

 Controller:
Code:
public void myAction()
{
MyApexClass.doSomething();
}

 
Apex Class:
Code:
public class MyApexClass
{

public static void doSomething() { // Some code goes here } }

 

Is this what you were looking for?

All Answers

XactiumBenXactiumBen
I think it is possible to do this, however you will need to have a function in your controller which is called by your button.  This function can then call the Apex Class function.

Example Code:

Visualforce Page:
Code:
<apex:commandButton action="{!myAction}" value="Clicky" />

 Controller:
Code:
public void myAction()
{
MyApexClass.doSomething();
}

 
Apex Class:
Code:
public class MyApexClass
{

public static void doSomething() { // Some code goes here } }

 

Is this what you were looking for?
This was selected as the best answer
sfdev1sfdev1
Yes, Thank you