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
Jonathan Wolff 7Jonathan Wolff 7 

Put Apex Execute command into button

Hello, I use a command in Apex execute from workbench to create xlsx.
The command in the xlsx is: 
XLSXGenerator.generate(new List<String>{'Apex', 'Create', 'XLSX', 'By Raymar'})
 I would like to execute the command with a button from account object. could you tell me if it is possible and how I can do it?
PriyaPriya (Salesforce Developers) 
Hi Jonathan,

Can you please check the below method

Now create a custom button:
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
use below JS:
{!REQUIRESCRIPT("/soap/ajax/30.0/connection.js")}
{!REQUIRESCRIPT("/soap/ajax/30.0/apex.js")}
if({!Account__c.Name}!=Null)
{
sforce.apex.execute("SampleClass","sampleMethod",{}"});
alert("This is {!Account__c.Name}");
}

Hope this is helpful!

Regards,
Ranjan