[SalesForce] Lightning component button not working

Below is my lightning component which calls a VF Page

<aura:component implements="force:lightningQuickAction" >

   <!-- attribute to accept Visualforce page's javascript method -->
   <aura:attribute name="TTDLetter" type="object"/>

   <!-- Button component to invoke PDF download -->
   <lightning:button label="PDF" 
        onclick="{!c.PDF}" />
</aura:component>

My VF page

<apex:page controller="MyController" renderAs="pdf" applyBodyTag="false">
<head>
<style>
body { font-family: 'Arial Unicode MS'; }

@page{
    size: letter;
    margin:10%;
    @top-left{
        content: "Dear,";
        font-family: Helvetica, Arial, sans-serif;
        font-size: 12px;
    }
    @bottom-right{
        content: "Yours Sincerely,";
        font-family: Helvetica, Arial, sans-serif;
        font-size: 10px;
    }
}

body {
        font-family: Helvetica, Arial, sans-serif;
        font-size: 11px;
}
    </style>
</head>
    <div align="right"><strong>Date</strong>: {!DAY(Today())} {!CASE(MONTH(Today()), 1, 'January', 2, 'February', 3, 'March', 4, 'April', 5, 'May', 6, 'June', 7, 'July', 8, 'August', 9, 'September', 10, 'October', 11, 'November', 12, 'December', 'Unknown')} {!YEAR(Today())}</div>
<center>
    <h1> Letter</h1>
    </center>
    <p>{!custom_object__C.Name__C}</p>    
</apex:page>

For the Lightning component If have created a quick action called "PDF", when I have clicked on PDF button from my object , I got a error stating :

A Component Error has occurred!.

Can anyone just state me where I got my error as i got stuck here

Best Answer

Before creating your lightning component, have you tried creating a new custom button with a 'Visualforce Page' content source ?

Displaying VF pages rendered as PDF via this button works fine for me in LEX.

You will have to make a few changes to your VF Page in order to make it available for your button :

<apex:page controller="MyController" renderAs="pdf" applyBodyTag="false">

becomes

<apex:page standardcontroller="yourObjectApiName" extensions="MyController" renderAs="pdf" applyBodyTag="false">

I hope this helps you.

Related Topic