Contents
To call an Apex class from custom button or link on the object detail page, create a VisualForce page and call the Apex class method via the action attribute to make it work. Following is some sample code showing how to do that. The action method invoked when this page is requested by the server. Click to see full answer.
How does batch apex work for a developer?
Batch Apex operates over small batches of records, covering your entire record set and breaking the processing down to manageable chunks. For example, a developer could build an archiving solution that runs on a nightly basis, looking for records past a certain date and adding them to an archive.
What can you do with batch apex in Lightning?
A developer can now employ batch Apex to build complex, long-running processes that run on thousands of records on the Lightning Platform. Batch Apex operates over small batches of records, covering your entire record set and breaking the processing down to manageable chunks.
Use either the ‘ action ‘ attribute (see warning below) or apex:commandButton ‘s on your page to invoke Apex logic. * You must also use the ‘ recordSetVar ‘ attribute on apex:page if you wish to create List View button.
How to call an apex class from a lightning component?
Now, let’s go ahead and define an apex class that can be used by this lightning component. The apex class should simply return the list of Account records with the Name and Type fields. To keep things simpler, we will just query the first 10 accounts using the LIMIT operator.
How do I add a lightning component to my App?
Now, navigate to Setup > Apps > New. Create a new custom app and add this lightning component tab to the custom tab and save it. That’s it. Switch to the Lightning experience now and navigate to the lightning component tab that we just setup. You should see a button like below
How to open a new window from Apex code?
As you probably know, you can’t open a window from Apex code. But you can change your VF page’s commandButton to a regular HTML input type=”button”, and add an onClick event handler that uses JavaScript to open a new window, setting the new window’s URL to the VF page you want the user to see.
What do you need to know about Apex code?
Apex provides the behind-the-scenes logic that runs on the Salesforce servers. You probably have some VF code like this: And you probably have a controller, written in Apex, that includes a method named SomeAction () that returns a PageReference to the page you want the user to see in the new window.
Can a custom button be used in Visualforce?
Currently however, the new ‘ Require CSRF protection on GET requests ‘ checkbox on the Visualforce page is only considered when the page is used to override the standard Delete button on an object. Hopefully support for Custom Button will arrive soon!