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

pdf generation using lightning components
Hi All,
I am generating Pdf for Account object using lightning components.in that client side controller file it will through
component.setParams() callback failed..i passed the accountId also but getting same error.can any one help me on this issue becuase i am new to lightning exp.
my code is
apex cls
public class TextVFPDFController {
public Account acc{get;set;}
public TextVFPDFController(){
Id accId = apexpages.currentpage().getparameters().get('id');
acc = [select id,Name from Account where id=: accId];
}
}
vf page
<apex:page controller="TextVFPDFController" renderAs="PDF">
{!acc.Name}
</apex:page>
component
<aura:component implements="force:appHostable,flexipage:availableForAllPageTypes,flexipage:availableForRecordHome,force:hasRecordId,forceCommunity:availableForAllPageTypes,force:lightningQuickAction" access="global" controller="TestAppController" >
<aura:attribute name = "accountId" type = "Account" />
<lightning:button variant = "brand" label = "Generate Pdf" onclick = "{!c.savePDF}" />
</aura:component>
client-side controller.js
({
savePDF : function(component, event, helper) {
var action = component.get("c.savePDFAccount");
action.setCallback(this, function(response) {
component.setParams({"recordId" : component.get("v.accountId")});
var state = response.getState();
if (state === "SUCCESS") {
component.set("v.recordId",response.getReturnValue());
alert('Attachment saved successfully');
}
else {
console.log("Unknown error");
}
});
$A.enqueueAction(action);
}
})
server-side controller.cls
public class TestAppController {
@auraEnabled
public static void savePDFAccount(String recordId){
PageReference pdfPage = new PageReference('/apex/TextVFPDF');
pdfPage.getParameters().put('Id',recordId);
Blob pdfContent = pdfPage.getContent();
Attachment attach1= new Attachment();
//attach1.ParentId = parentId;
attach1.Name = 'Test Attachment for PDF';
attach1.Body = pdfContent;
attach1.contentType = 'application/pdf';
insert attach1;
}
}
and the error is
Uncaught Error in $A.getCallback() [component.setParams is not a function]
Callback failed: apex://TestAppController/ACTION$savePDFAccount
can any one help this issue
thanks in advance
I am generating Pdf for Account object using lightning components.in that client side controller file it will through
component.setParams() callback failed..i passed the accountId also but getting same error.can any one help me on this issue becuase i am new to lightning exp.
my code is
apex cls
public class TextVFPDFController {
public Account acc{get;set;}
public TextVFPDFController(){
Id accId = apexpages.currentpage().getparameters().get('id');
acc = [select id,Name from Account where id=: accId];
}
}
vf page
<apex:page controller="TextVFPDFController" renderAs="PDF">
{!acc.Name}
</apex:page>
component
<aura:component implements="force:appHostable,flexipage:availableForAllPageTypes,flexipage:availableForRecordHome,force:hasRecordId,forceCommunity:availableForAllPageTypes,force:lightningQuickAction" access="global" controller="TestAppController" >
<aura:attribute name = "accountId" type = "Account" />
<lightning:button variant = "brand" label = "Generate Pdf" onclick = "{!c.savePDF}" />
</aura:component>
client-side controller.js
({
savePDF : function(component, event, helper) {
var action = component.get("c.savePDFAccount");
action.setCallback(this, function(response) {
component.setParams({"recordId" : component.get("v.accountId")});
var state = response.getState();
if (state === "SUCCESS") {
component.set("v.recordId",response.getReturnValue());
alert('Attachment saved successfully');
}
else {
console.log("Unknown error");
}
});
$A.enqueueAction(action);
}
})
server-side controller.cls
public class TestAppController {
@auraEnabled
public static void savePDFAccount(String recordId){
PageReference pdfPage = new PageReference('/apex/TextVFPDF');
pdfPage.getParameters().put('Id',recordId);
Blob pdfContent = pdfPage.getContent();
Attachment attach1= new Attachment();
//attach1.ParentId = parentId;
attach1.Name = 'Test Attachment for PDF';
attach1.Body = pdfContent;
attach1.contentType = 'application/pdf';
insert attach1;
}
}
and the error is
Uncaught Error in $A.getCallback() [component.setParams is not a function]
Callback failed: apex://TestAppController/ACTION$savePDFAccount
can any one help this issue
thanks in advance
Greetings to you!
You need to change the code from the client-side controller.
I hope it helps you.
Kindly let me know if it helps you and close your query by marking it as solved so that it can help others in the future.
Thanks and Regards,
Khan Anas
You can create PDF using email template and can generate PDF in lightning using Apex. Check out this link (https://salesforcecodex.com/salesforce/send-email-template-as-pdf-attachment-using-salesforce-apex/).
Thank You,
Dhanik