In classic, For calling apex class from custom button the class must be global. You can create custom button from salesforce org using javascript. Following the steps, After creating apex class (global). Goto --> Setup --> Object --> Buttons, links and Actions section Click New Button or Link Enter the Name of the button Behaviour : Execute Javascript Content source : On-Click Javascript The sample js code for the button is
{!REQUIRESCRIPT("/soap/ajax/30.0/connection.js")}
{!REQUIRESCRIPT("/soap/ajax/30.0/apex.js")}
if({!AAA__c.Name}!=Null)
{
sforce.apex.execute("MyClass","myMethod",{}"});
alert("This is {!AAA__c.Name}");
}
In Lightening Create a lightning component that implements force:lightningQuickAction. We can override our action using these component. Then we can call apex class by seting our client side controller to a callback function. Use this code
var action = cmp.get("c.YourMethodName");
action.setParams({
param1: cmp.get("v.something1"),
param2: cmp.get("v.something2")
});
action.setCallback(this, function(response) {
if (response.state === "SUCCESS"){
var serverResponse = response.getReturnValue();
}
});
$A.enqueueAction(action);
In classic, For calling apex class from custom button the class must be global. You can create custom button from salesforce org using javascript. Following the steps, After creating apex class (global). Goto --> Setup --> Object --> Buttons, links and Actions section Click New Button or Link Enter the Name of the button Behaviour : Execute Javascript Content source : On-Click Javascript The sample js code for the button is
{!REQUIRESCRIPT("/soap/ajax/30.0/connection.js")}
{!REQUIRESCRIPT("/soap/ajax/30.0/apex.js")}
if({!AAA__c.Name}!=Null)
{
sforce.apex.execute("MyClass","myMethod",{}"});
alert("This is {!AAA__c.Name}");
}
In Lightening Create a lightning component that implements force:lightningQuickAction. We can override our action using these component. Then we can call apex class by seting our client side controller to a callback function. Use this code
var action = cmp.get("c.YourMethodName");
action.setParams({
param1: cmp.get("v.something1"),
param2: cmp.get("v.something2")
});
action.setCallback(this, function(response) {
if (response.state === "SUCCESS"){
var serverResponse = response.getReturnValue();
}
});
$A.enqueueAction(action);
In classic,
For calling apex class from custom button the class must be global.
You can create custom button from salesforce org using javascript.
Following the steps,
After creating apex class (global).
Goto --> Setup --> Object --> Buttons, links and Actions section
Click New Button or Link
Enter the Name of the button
Behaviour : Execute Javascript
Content source : On-Click Javascript
The sample js code for the button is
In Lightening
Create a lightning component that implements force:lightningQuickAction.
We can override our action using these component.
Then we can call apex class by seting our client side controller to a callback function.
Use this code
Regards
Ajvad Aju
All Answers
In classic,
For calling apex class from custom button the class must be global.
You can create custom button from salesforce org using javascript.
Following the steps,
After creating apex class (global).
Goto --> Setup --> Object --> Buttons, links and Actions section
Click New Button or Link
Enter the Name of the button
Behaviour : Execute Javascript
Content source : On-Click Javascript
The sample js code for the button is
In Lightening
Create a lightning component that implements force:lightningQuickAction.
We can override our action using these component.
Then we can call apex class by seting our client side controller to a callback function.
Use this code
Regards
Ajvad Aju