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
Shubham Bansal 45Shubham Bansal 45 

I want to pass record id to vf page on button click of lightning component.

Explaination: 

I have a lightning component on record page and on that component i have a generate pdf button on the button click i have to pass record id to vf page and generate pdf.

i have created my vf page. but i am not able to pass record id and and show that vf page .

Any help is appreciated .Its urgent.

Danish HodaDanish Hoda
Hi Shubham,
May I know how are you going to display the pdf once it is generated on button click?
Danish HodaDanish Hoda
As a workaround, you can use navigation functionality on lightning component, when clicked set the recordId as a gating paratmeter to the naviurl and use the extension/custom controller's constructor to get the Id of the record from the url parameter.
Navigation would be like this:
let recordId = component.get("v.recordId");
let urlVar = <VFPageLink>+'/?&rId='+recordId;
        
        var eUrl= $A.get("e.force:navigateToURL");
        eUrl.setParams({
            "url": urlVar
        });
        eUrl.fire();

 
Shubham Bansal 45Shubham Bansal 45
I am using this but my record id on the controller appear as null.
 
Shubham Bansal 45Shubham Bansal 45

i have to display my pdf on the new tab of the browser .

My vf page is code is working fine the only problem is the id i want.

Danish HodaDanish Hoda
You can use "navigateToURL" functionality as I have mentioned above
Shubham Bansal 45Shubham Bansal 45

My js code:

  exportPdf: function(component, event, helper) {
  
    var recordId = component.get("v.recordId");   
        console.log('Recardid',recordId);
    let urlVar = 'https://project--acc.cs18.visual.force.com/apex/demoPdf?core.apexpages.request.devconsole=1'+'/?&rId='+recordId;
        console.log('urlVar',urlVar);
        var eUrl= $A.get("e.force:navigateToURL");
        eUrl.setParams({
            "url": urlVar
        });
        eUrl.fire();
    }

 

My apex code:

 


    public  List<ParentWrap> parentWrapperList {get;set;}
    
    public PP4_PartnerBusinessPlan(ApexPages.StandardController controller){
        String recordId = ApexPages.currentPage().getParameters().get('rId'); 
      Partner_Business_Plan__c abc =(Partner_Business_Plan__c) controller.getRecord();
         system.debug('abc'+abc);
        system.debug('shdsd'+recordId);

And so on...

 

I have doing everything like you say already but  system.debug('shdsd'+recordId); gives null
 

 

 

Danish HodaDanish Hoda
hi Shubham,
Plz update your navigate Url as below :
let urlVar = 'https://project--acc.cs18.visual.force.com/apex/demoPdf?'+'rId='+recordId;

 
Shubham Bansal 45Shubham Bansal 45
Thanks now it's working, the issue is in the controller. Thanks for your help.
Shubham Bansal 45Shubham Bansal 45

Have you any idea how to change the name of pdf opened in new name according to the record name.

I try by using this: Apexpages.currentPage().getHeaders().put('content-disposition', 'attachment; filename='+pp.Name+'.pdf');

but it downloads pdf instead of showing it in new tab.

namrata vora 2namrata vora 2
I faced the same issue, that i was getting the id as null...but here's the mistake that i made:
public PDMS_CRED_PDFGenerator(ApexPages.StandardController controller) {
        currentRecordId  = ApexPages.CurrentPage().getparameters().get('id');
        system.debug('currentRecordId///'+currentRecordId);
    }
instead of:
public PDMS_CRED_PDFGenerator() {
        currentRecordId  = ApexPages.CurrentPage().getparameters().get('id');
        system.debug('currentRecordId///'+currentRecordId);
    }
for your scenario you cannot use 'ApexPages.StandardController controller' as a parameter for constructor, it should not receive any parameter actually, so in short the 2nd way will work.

Thanks,
Namrata