function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
V AnandV Anand 

How to generate PDF file for selected records in contacts view?

Hi..........

 

I want to generate PDF file for selected (check box selected in contact list"All" view) contact in the view...

 

For that I created a visualforce page custom button in contact list search layout. Now I selected some contacts through checkbox which is available in Contact list view...

 

How can I achieve above  requirement? anyone help me......

 

Shell I neet to write any apex code for this.?.............

Best Answer chosen by Admin (Salesforce Developers) 
JitendraJitendra

Lets take example of Lead. You have button on List view of Lead.

 

Visualforce page :

<apex:page standardController="Lead" recordSetVar="anyName" extensions="YOUR_CONTYROLLER_EXTENSION_CLASS" >
<!-- Your logic here to display the record using repeater or datatable -->
</apex:page>

 

Apex class : YOUR_CONTYROLLER_EXTENSION_CLASS

public class YOUR_CONTYROLLER_EXTENSION_CLASS
{
	ApexPages.StandardSetController setCon;  
	
	public YOUR_CONTYROLLER_EXTENSION_CLASS(ApexPages.StandardSetController controller)
    {
		setCon = controller;
		Set<Id> leadIDSet = new Set<id>();
		for ( Lead led : (Lead[])setCon.getSelected() )
        {
               leadIDSet.add(led.id);               
        }
		
		//Here SET leadIDSet contains the ID of all the lead selected
	}

}

 

All Answers

JitendraJitendra

Hi,

 

You will need Apex class (Controller Extension) and Visualforce page.

 

1. Create a Custom Button of type List and add on List View. The URL of button should be your Visualforce page.

2. When you select the contacts and click on "Your Custom Button", the ID of selected Contacts will be available to your Controller Extension.

3. Populate all your record in Visual force and tell render as pdf.

Thats it !!!

 

If you need tutorial to how to create PDF, please look into below article:

http://wiki.developerforce.com/page/Creating_Professional_PDF_Documents_with_CSS_and_Visualforce

V AnandV Anand
Thank you for your valuable reply... But How to handle selected records in list for?extensions controller....could you please provide sample code snipnet for extension controller.?
JitendraJitendra

Lets take example of Lead. You have button on List view of Lead.

 

Visualforce page :

<apex:page standardController="Lead" recordSetVar="anyName" extensions="YOUR_CONTYROLLER_EXTENSION_CLASS" >
<!-- Your logic here to display the record using repeater or datatable -->
</apex:page>

 

Apex class : YOUR_CONTYROLLER_EXTENSION_CLASS

public class YOUR_CONTYROLLER_EXTENSION_CLASS
{
	ApexPages.StandardSetController setCon;  
	
	public YOUR_CONTYROLLER_EXTENSION_CLASS(ApexPages.StandardSetController controller)
    {
		setCon = controller;
		Set<Id> leadIDSet = new Set<id>();
		for ( Lead led : (Lead[])setCon.getSelected() )
        {
               leadIDSet.add(led.id);               
        }
		
		//Here SET leadIDSet contains the ID of all the lead selected
	}

}

 

This was selected as the best answer
V AnandV Anand

Thank you for your help........

arronleearronlee

I am so glad to see that your problem had been solved sooner after you put it forward. As for myself, using the CODE to generate PDFs is too complicated for me. And I have to admit that choosing a fine 3rd party tool is so important because only the one whose way of processing is simple and fast can make the work much more convenient to operate. Checking its free trial page according to its tutorials about how to get the PDF generating work started is also very neccesary. I hope you good luck all the time.



Best regards,
Arron