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.setRedirect(true);
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];
system.debug('***'+rRecord+'---'+rpRecord);
sendClientRecord();
}
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;
pdf.getParameters().put('id',rpid);
pdf.getParameters().put('test1var',test1);
pdf.getParameters().put('test2var',test2);
pdf.setRedirect(true);
Blob pdfBody;
if(!test.isRunningTest()){
pdfBody = pdf.getContentAsPDF();
}
else
{
pdfBody = blob.valueof('TEST');
}
list<Attachment> at=[select id,name,body from Attachment where ParentId=:rpid];
String name;
if(at.size()!=0)
name=rRecord.Name+ '-' +'RenewalProduct'+at.size()+'.pdf';
else
{
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]');
system.debug('***222'+liststr);
email.setSubject('');
email.setToAddresses(liststr);
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();
efa.setFileName(attach.Name);
efa.setBody(pdfBody);
email.setFileAttachments(new Messaging.EmailFileAttachment[] {efa});
Messaging.SendEmailResult [] r = Messaging.SendEmail(new Messaging.SingleEmailMessage[] {email});
PageReference pageRef = new PageReference('/'+rpid);
pageRef.setRedirect(true);
// return pageRef;
}
Here I am not getting any value. once calling page from this method. Please Help me in this!