You need to sign in to do that
Don't have an account?

how to call an apex controller from lightning component button?
public class BatchApexController{ public void callBatch(){ database.executebatch(new LoanofficerBatch()); database.executebatch(new RealtorBatch()); database.executebatch(new BuilderBatch()); } }please help
You need to create a lightning component that implements force: lightningQuickAction. After this, you will be able to override your Action using this lightning component. You can program your client-side controller to set a callback function, that would call your Apex class to perform some logical calculation. This is fairly simple and you can find numerous example on the trailhead.
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);
Check out this link:
https://trailhead.salesforce.com/en/content/learn/modules/lex_dev_lc_basics/lex_dev_lc_basics_server
https://wedgecommerce.com/calling-apex-controller-method-lightning-component/
I hope you find the above solution helpful. If it does, please mark as Best Answer to help others too.
Thanks,
Ajay Dubedi
You can use below code first to create a component
Component
JS Controller
Once this is done, Follow the below step