You need to sign in to do that
Don't have an account?
Hanumantha Rao 6
if user selects 10 Products and these are associated to 3 different product types, 3 PDF files has to be generated and download in to local system.
Hi I have a requirement please find the below ,
REQ : Create a new Button on Opportunity detail page, once user click on the button need to show the Product records in the vf page with input check box in front of the each record.
Once user selects records and click on save leads to download the PDF document based on Product Type
Ex: if user selects 10 Products and these are associated to 3 different product types, 3 PDF files has to be generated and download in to local system.
Work around : i have created VF page for dispalying all products and this VF page created a button called Save Lead, in this VF page i selected 3 records based on the product type and i click the save lead button ,automatically PDF has to be generated ,only 1 pdf file generated ,but i selected 3 records.
Example: if i select 3 records in VF page 3 files has to be generate ------> but my code it work only download 1 pdf file, please find the below code and please suggest me where am missing or anyone done already this requirement pls send the code, i have checked all the blogs but no luck
VF Page :
Controller :
public class ProductPDFController {
id oppid;
//Our collection of the class/wrapper objects ProductWrapper
public List Product2List {get; set;}
public ProductPDFController (){
oppid = System.currentPageReference().getParameters().get('oppid');
}
//This method uses a simple SOQL query to return a List of Product2s
public List getProducts() {
if(Product2List == null) {
Product2List = new List();
for(Product2 c: [SELECT Id, Family, IsActive, ProductCode, Name FROM Product2 where Id=:oppid AND isactive=true AND ID IN (select product2id from opportunityLineItem where product2id!=null)]) {
// As each Product2 is processed we create a new ProductWrapper object and add it to the Product2List
Product2List.add(new ProductWrapper(c));
}
}
return Product2List;
}
public pagereference Download() {
set selectedTypes = new set();
//We create a new list of Product2s that we be populated only with Product2s if they are selected
List selectedProduct2s = new List();
//We will cycle through our list of ProductWrappers and will check to see if the selected property is set to true, if it is we add the Product2 to the selectedProduct2s list
for(ProductWrapper cCon: Product2List) {
if(cCon.selected == true) {
selectedProduct2s.add(cCon.con);
}
}
// Now we have our list of selected Product2s and can perform any type of logic we want, sending emails, updating a field on the Product2, etc
System.debug('These are the selected Product2s...');
for(Product2 con: selectedProduct2s) {
system.debug(con);
selectedTypes.add(con.family);
}
Product2List=null; // we need this line if we performed a write operation because getProduct2s gets a fresh list now
Pagereference pageref;
pageref = page.downloadpdf;
pageRef.getParameters().put('recordsize',string.valueof(selectedTypes.size()));
pageref.setRedirect(false);
return pageref;
}
// This is our wrapper/container class. A container class is a class, a data structure, or an abstract data type whose instances are collections of other objects. In this example a wrapper class contains both the standard salesforce object Product2 and a Boolean value
public class ProductWrapper {
public Product2 con {get; set;}
public Boolean selected {get; set;}
//This is the contructor method. When we create a new ProductWrapper object we pass a Product2 that is set to the con property. We also set the selected value to false
public ProductWrapper(Product2 c) {
con = c;
selected = false;
}
}
}
Download VF page :
Controller :
public with sharing class contactquery {
public string renderAs{get;set;}
public contactquery(){
//figure out if the user passed in the pdf url variable and if it is set to true.
integer size = integer.valueof(ApexPages.currentPage().getParameters().get('recordsize'));
for(integer i=1;i runmethod(i);
}
}
public void runmethod(integer i){
renderAs = 'pdf';
string fileName = 'My PDF Report '+date.today()+'.pdf';
Apexpages.currentPage().getHeaders().put('content-disposition', 'attachment; filename='+fileName+'('+i+')');
}
}
REQ : Create a new Button on Opportunity detail page, once user click on the button need to show the Product records in the vf page with input check box in front of the each record.
Once user selects records and click on save leads to download the PDF document based on Product Type
Ex: if user selects 10 Products and these are associated to 3 different product types, 3 PDF files has to be generated and download in to local system.
Work around : i have created VF page for dispalying all products and this VF page created a button called Save Lead, in this VF page i selected 3 records based on the product type and i click the save lead button ,automatically PDF has to be generated ,only 1 pdf file generated ,but i selected 3 records.
Example: if i select 3 records in VF page 3 files has to be generate ------> but my code it work only download 1 pdf file, please find the below code and please suggest me where am missing or anyone done already this requirement pls send the code, i have checked all the blogs but no luck
VF Page :
Controller :
public class ProductPDFController {
id oppid;
//Our collection of the class/wrapper objects ProductWrapper
public List Product2List {get; set;}
public ProductPDFController (){
oppid = System.currentPageReference().getParameters().get('oppid');
}
//This method uses a simple SOQL query to return a List of Product2s
public List getProducts() {
if(Product2List == null) {
Product2List = new List();
for(Product2 c: [SELECT Id, Family, IsActive, ProductCode, Name FROM Product2 where Id=:oppid AND isactive=true AND ID IN (select product2id from opportunityLineItem where product2id!=null)]) {
// As each Product2 is processed we create a new ProductWrapper object and add it to the Product2List
Product2List.add(new ProductWrapper(c));
}
}
return Product2List;
}
public pagereference Download() {
set selectedTypes = new set();
//We create a new list of Product2s that we be populated only with Product2s if they are selected
List selectedProduct2s = new List();
//We will cycle through our list of ProductWrappers and will check to see if the selected property is set to true, if it is we add the Product2 to the selectedProduct2s list
for(ProductWrapper cCon: Product2List) {
if(cCon.selected == true) {
selectedProduct2s.add(cCon.con);
}
}
// Now we have our list of selected Product2s and can perform any type of logic we want, sending emails, updating a field on the Product2, etc
System.debug('These are the selected Product2s...');
for(Product2 con: selectedProduct2s) {
system.debug(con);
selectedTypes.add(con.family);
}
Product2List=null; // we need this line if we performed a write operation because getProduct2s gets a fresh list now
Pagereference pageref;
pageref = page.downloadpdf;
pageRef.getParameters().put('recordsize',string.valueof(selectedTypes.size()));
pageref.setRedirect(false);
return pageref;
}
// This is our wrapper/container class. A container class is a class, a data structure, or an abstract data type whose instances are collections of other objects. In this example a wrapper class contains both the standard salesforce object Product2 and a Boolean value
public class ProductWrapper {
public Product2 con {get; set;}
public Boolean selected {get; set;}
//This is the contructor method. When we create a new ProductWrapper object we pass a Product2 that is set to the con property. We also set the selected value to false
public ProductWrapper(Product2 c) {
con = c;
selected = false;
}
}
}
Download VF page :
PDF Download example
Controller :
public with sharing class contactquery {
public string renderAs{get;set;}
public contactquery(){
//figure out if the user passed in the pdf url variable and if it is set to true.
integer size = integer.valueof(ApexPages.currentPage().getParameters().get('recordsize'));
for(integer i=1;i runmethod(i);
}
}
public void runmethod(integer i){
renderAs = 'pdf';
string fileName = 'My PDF Report '+date.today()+'.pdf';
Apexpages.currentPage().getHeaders().put('content-disposition', 'attachment; filename='+fileName+'('+i+')');
}
}
you can create three different method for three PDF generation ... and with help of IF conditon you can call what ever method you want to call
for Example,
public pagerefrence PDF1(){
//LOGIC
}
public pagerefrence PDF2(){
//LOGIC
}
public pagerefrence PDF3(){
//LOGIC
}
public void doCheckNumerOfPDF(){
if(product type is THree diff)
{
PDF1();
PDF2();
PDF3();
else {
PDF1();
}
}
Let me know if i am worng at any place.
Thanks,
Keyur Modi
Thanks for reply ,
but in my vf page displaying 25 records , if i select morethan 5 record how the methods known these record contain wich method like this.... or please do modification in my code and reply ASAP.it would be great helpfull for me
what you can do is ... you can take list of the records you can iterate it and you can count the number with the similar type and that you can pass it to doCheckNumerOfPDF this method through parameter,
for Example.
List<product2> lstProduct=new List<product2>();
lstProduct=[SELECT id,name,Type FROM product2];
int countSimilarType=0;
for(product2 eachproduct:lstProduct){
if(eachproduct.Type =="Type1){
countSimilarType=countSimilarType+1;
}
}
public void doCheckNumerOfPDF(countSimilarType){
if(countSimilarType==3 || countSimilarType>3)
{
PDF1();
PDF2();
PDF3();
else {
PDF1();
}
}
please try like this.
Thanks,
Keyur Modi