I have written one VF page,1 extensions on opportunity detail page with show products button.Once i click show products,it will show all products present in that current opportunity.List of products will be wrapper class.So on selecting particular opportunityline items it should be downloaded as pdf.No. of pdf downloaded depends on Product_Type__c field.If total 2 types of opportunity line items are selected then on click of save the records it will download 2 separate pdf for different product type.Currently i m getting error.I am not able to rendered as pdf for any opportunity lineitems.Please help.I have edited the code with now one extensions and 2 vf page.2nd page will d one to be rendered as pdf.I am not sure if i am correct.Please suggest.
VF Page :
<apex:form >
<apex:pageBlock id="pageBlock1">
<apex:pageBlockButtons >
<apex:commandButton action="{!saveRecords}" value="Save the records" reRender="pageBlock1" />
<apex:commandButton action="{!CancelRecords}" value="Cancel" reRender="pageBlock1"/>
</apex:pageBlockButtons>
<apex:pageblockTable value="{!List}" var="pro" id="details">
<apex:column >
<apex:facet name="header">
<apex:inputCheckbox />
</apex:facet>
<apex:inputCheckbox value="{!pro.isSelected}" id="InputId"/>
</apex:column>
<apex:column value="{!pro.pr.Name}"/>
<apex:column value="{!pro.pr.ProductCode}"/>
<apex:column value="{!pro.pr.Quantity}"/>
<apex:column value="{!pro.pr.TotalPrice}"/>
<apex:column value="{!pro.pr.UnitPrice}"/>
<apex:column value="{!pro.pr.Product_Type__c}"/>
</apex:pageblockTable>
</apex:pageBlock>
</apex:form>
</apex:page>
Extensions ProductPDFController :
public with sharing class ProductPDFController {
// ID OpportunityId;
public string renderAs{get;set;}
public list<wrapProducts> wrapProductsList { get; set; }
public list<OpportunityLineItem> selectedProducts{get;set;}
ID OpportunityId=ApexPages.currentPage().getParameters().get('Id');
public ProductPDFController(ApexPages.StandardController controller) {
}
public List<wrapProducts> getList()
{
wrapProductsList=new list<wrapProducts>();
List<OpportunityLineItem> prolist= Database.Query('Select id,Opportunity.Name,Name,ProductCode,Quantity,TotalPrice,UnitPrice,Product_Type__c from OpportunityLineitem WHERE Opportunity.Id=:OpportunityId');
for(OpportunityLineItem pr1:prolist){
wrapProductsList.add(new wrapProducts(pr1));
}
return wrapProductsList;
}
public PageReference CancelRecords() {
PageReference pageref=new PageReference('/'+OpportunityId);
return pageref;
}
public PageReference saveRecords() {
selectedProducts=new list<OpportunityLineItem>();
Pagereference pageref = page.pdfPage;
pageref.setRedirect(true);
for(wrapProducts wrappro:wrapProductsList){
if(wrappro.isSelected==true){
selectedProducts.add(wrappro.pr);
System.debug('value of page :::: '+wrappro.pr);
Integer type1 = 0;
Integer type2 = 0;
Integer type3 = 0;
Integer type4 = 0;
Integer type5 = 0;
for(OpportunityLineItem spdt:selectedProducts ){
if(spdt.Product_Type__c =='Combined') {
type1 = type1 + 1;
}else if(spdt.Product_Type__c =='Hardware'){
type2 = type2 + 1;
}else if(spdt.Product_Type__c =='Programming'){
type3 = type3 + 1;
}else if(spdt.Product_Type__c =='Software'){
type4 = type4 + 1;
}else{
type5 = type5 + 1;
}
doCheckNumerOfPDF(type1,type2,type3,type4,type5);
}
pageref.getParameters().put('id',wrappro.pr.OpportunityId);
}
}
return pageref;
}
public class wrapProducts{
public OpportunityLineItem pr{get;set;}
public boolean isSelected{get;set;}
public wrapProducts(OpportunityLineItem p){
pr=p;
isselected=false;
}
}
public void doCheckNumerOfPDF(Integer i,Integer j,Integer k,Integer l,Integer m){
if(i!= 0){
pdf1();
}else if(j!=0){
pdf2();
}else if(k!=0){
pdf3();
}else if(l!=0){
pdf4();
}else {
pdf5();
}
}
public PageReference pdf1(){
return null;
}
public PageReference pdf2(){
return null;
}
public PageReference pdf3(){
return null;
}
public PageReference pdf4(){
return null;
}
public PageReference pdf5(){
return null;
}
}
VF Page(Rendered as PDF):
<apex:page standardController="Opportunity" renderAs="pdf" sidebar="False" extensions="ProductPDFController">
<apex:form >
<apex:pageBlock id="pageBlock1">
<apex:pageblockTable value="{!selectedProducts}" var="pro" id="details">
<apex:column >
<apex:facet name="header">
</apex:facet>
</apex:column>
<apex:column value="{!pro.Name}"/>
<apex:column value="{!pro.ProductCode}"/>
<apex:column value="{!pro.Quantity}"/>
<apex:column value="{!pro.TotalPrice}"/>
<apex:column value="{!pro.UnitPrice}"/>
<apex:column value="{!pro.Product_Type__c}"/>
</apex:pageblockTable>
</apex:pageBlock>
</apex:form>
</apex:page>