I am creating a VF page where I have to select date and filter data and using button I need to send the another VF page as PDF with same data in email as attachment. When I selecting Date from 1st VF page and on click button passing the selected date and record Id to Another VF page (Which I need to send as pdf). I am getting the Data in 2nd page constructor but once I am sending the same page using single messaging its throwing error saying that 'List has no row fro assignment.'

Using below code I am passing Id and Dates.

Pagereference pr = Page.RenewalProductPageTemplate;
    pr.getParameters().put('searchFilter1', rpid);
    pr.getParameters().put('searchFilter2', test1);
    pr.getParameters().put('searchFilter3', test3);
    return pr;

Controller of 2nd Page.

    rpid  = ApexPages.currentPage().getParameters().get('searchFilter1'); 
    test1 = ApexPages.currentPage().getParameters().get('searchFilter2');
    test2 = ApexPages.currentPage().getParameters().get('searchFilter3');

    rRecord = [Select id,name,Family__r.name ,Family__r.Email_ID__c from Renewal__c where Id =:rpid]; 

    rpRecord= [Select id,name,Company__r.name,Client_Name__c,Client_Name__r.name,Product__r.name,
                    Renewal__r.Family__r.name, Premium_Amount__c,Premium_Due_Date__c,Plan__c from Renewal_Product__c 
                    where  Renewal__c=:rpid];



In above 2nd page (Which I need to send as PDF) I am geeitng data(rpid, test1, test2). And I am geeting the debug. But once calling [sendClientRecord();] Method for sending mail the same constructor not working.

Below is sendClientRecord() Method code piece.

 public void sendClientRecord(){ ;

    PageReference pdf;
    pdf = Page.RenewalProductPageTemplate;


    Blob pdfBody;
        pdfBody = pdf.getContentAsPDF();
        pdfBody = blob.valueof('TEST');
    list<Attachment> at=[select id,name,body from Attachment where ParentId=:rpid];
    String name;
        name=rRecord.Name+ '-' +'RenewalProduct'+at.size()+'.pdf';
        name=rRecord.Name + '-' +'SendRenProdEmailwithButtonpage.pdf';
    Attachment attach = new Attachment();
    attach.ParentId =rpid;
    attach.name = name;
    attach.body = pdfBody ;
    System.debug('tId '+rpid);
    INSERT attach;

    Messaging.SingleEmailMessage email = new Messaging.SingleEmailMessage();

    List<String> liststr = new List<String>();

    liststr.add('[email protected]');


    email.setToAddresses(liststr); //Used SOQL to retrieve addresses in the address
    email.setPlainTextBody('Please find attached PDF');
    // rpRecord. = true;

    Messaging.Emailfileattachment efa = new Messaging.Emailfileattachment();
    email.setFileAttachments(new Messaging.EmailFileAttachment[] {efa});

    Messaging.SendEmailResult [] r = Messaging.SendEmail(new Messaging.SingleEmailMessage[] {email}); 

    PageReference pageRef = new PageReference('/'+rpid);

   // return pageRef;


Here I am not getting any value. once calling page from this method. Please Help me in this!

1 Answer 1


This may have been included in the code you didn't post, but both rRecord and rpRecord are of type list<Renewal__c>. It would seem to me that if you use Limit 1 on both of those queries, they can just be Renwal__c records and won't need to be lists. Otherwise, your code will need to get the values of rRecord[0] and rpRecord[0] which could possibly be part of the problems you're having.

Unless you're wanting to preview the email, you'll want to use the original button to send the email with the attachments because neither your email or the attachment should have any active content on them, especially if they're both being PDF'd. The attachment in particular must be created using HTML 4.1 and CSS 2.


I also see where it appears that you've declare a VOID method yet are trying to return a redirected PageReference. A VOID method can't return anything!

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .