You need to sign in to do that
Don't have an account?
Jonathan Wolff 7
Create a button to start XLSX-Genarator Apex
Hello, I have a XLSXGenerator apex. I want to start the apex by using a button. For now I can only start it by workbench.
In workbench i make apex execute with the command:
The XLSXGenarator code is:
In workbench i make apex execute with the command:
XLSXGenerator.generate(new List<String>{})
The XLSXGenarator code is:
public class XLSXGenerator { //public static String generate(List<String> textList) { public static String generate(List<String> AccList) { // Build XLSX File Content PageReference xlsxTemplate = page.XLSXTemplate; // xlsxTemplate.getParameters().put('textList', System.JSON.serialize(textList)); xlsxTemplate.getParameters().put('AccList', System.JSON.serialize(AccList)); Blob xlsxContent; if (Test.isRunningtest()) { xlsxContent = Blob.valueOf('Sample'); } else { xlsxContent = xlsxTemplate.getContent(); } // Build XLSX File Frame StaticResource xlsxTemplateFrame = [SELECT Body FROM StaticResource WHERE Name = 'XLSXTemplateFrame' LIMIT 1]; Zippex xlsx = new Zippex(xlsxTemplateFrame.Body); // Add the Content to the Frame to complete the File xlsx.addFile('xl/worksheets/sheet1.xml', xlsxContent, null); // Save XLSX File ContentVersion cv = new ContentVersion(); String title = 'XLSXExample'; cv.Title = title; cv.PathOnClient = title + ' - ' + DateTime.now() + '.xlsx'; cv.VersionData = xlsx.getZipArchive(); insert cv; Id contentDocumentid = [SELECT Id FROM ContentDocument WHERE LatestPublishedVersionId = :cv.Id].Id; return URL.getOrgDomainUrl().toExternalForm() + '/sfc/servlet.shepherd/document/download/' + contentDocumentid; } }
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