I have a requirement where i have to generate multiple pdf file based upon the value of a field called Location.
If the Location is India, then i get all the records whose location is india and make a list from it which is then sent to visualforce page. The visualforce page is rendered as pdf. So, I get a Pdf.
Now, there will be other record as well whose location is some other value like USA, Demark, Norway, China e.t.c. For all these location i have to generate other pdf files as well. How do i achieve this?
My visualforce page is something like this
<apex:page controller="MyController" renderAs="pdf">
<apex:form >
<apex:pageBlock >
<apex:pageBlockTable value="{!recordList}" var="record">
<apex:column value="{!record.Name}"/>
</apex:pageBlockTable>
</apex:pageBlock>
</apex:form>
</apex:page>
In the visualforce page i get a list of records and i am printing the name of each record.
public without sharing class MyController {
List<SomeReport> reportList;
public List<SomeReport> getReportList() {
equipmentList = [SELECT Id, Name FROM SomeReport];
return equipmentList;
}
}
//Location is a field in the object SomeReport
In the apex i am sending all the record. Now i want to create a list of record with multiple locations and create multiple pdf. How do i achieve this?
public void UpdateContents()
{
String[] siteList = new String[]{'India','USA'};
for(String siteValue: siteList) {
try {
PageReference pageRef = Page.InvoicePage;
pageRef.getParameters().put('siteName', 'Kathmandu');
PageContents = pageRef.getContent().toString().replace
('<html style="display:none !important;">', '<html>');
} catch(exception ex) {
System.debug('Inside catch block');
PageContents = 'An error has occurred while trying to generate this invoice. Please contact customer service.';
}
}
}
I did not use blob as i don't know about it.