1

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>
1

What appears to me to be causing your problem is that you're using Visualforce components that are Unsafe for use when Rendering as PDF, in particular <apex:form>, <apex:pageBlock> and <apex:pageBlockTable>. Also, <apex:column> is flagged for "Use with Caution". You'll want to redesign your page using standard HTML based around a along with <tr>, <td> and <th> tags, etc to create the cells. Then use an <apex:repeat> tag to fill the table. Also, try printing without the renderAs=Pdf to make certain your page works, then add the renderAs when it's looking like you want it which will confirm whether or not your html mark-up is correct for use with the pdf render engine which only supports CSS 2.1.

4
  • i have modified pdfPage vf page and extensions also .Now i am not getting selected records inside the pdf page.No data coming to pdf.No able to find root cause for this issue.
    – Jack vardy
    Oct 29 '15 at 17:49
  • Were you getting them before you modified the page? I don't see where you've edited your post with revised code. Without it, there's nothing I can tell you.
    – crmprogdev
    Oct 29 '15 at 18:02
  • It is working if i update line to below in pdfPage.vfp <apex:pageblockTable value="{!selectedProducts}" var="pro" id="details"> to <apex:pageblockTable value="{!List}" var="pro" id="details"> And update <Apex:column value accordingly> but when i changed pageblockTable to selectedProducts then it is not giving selected records from wrapper class.Dont know whats the issue.I am not getting any exception or error also.So difficult to find root cause.
    – Jack vardy
    Oct 30 '15 at 3:32
  • Based on your original VF page, I'd expect you to need to have nested repeats. The first one being on pro and the inner one on pr.
    – crmprogdev
    Oct 30 '15 at 14:01

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.