On Account page i have a button which on click will display a vf page with its related opportunities with checkbox.

I want on selected records which i click generate pdf, it will display those records in a pdf format.


public class OppControllerr {

Private Id accID;

public OppControllerr(){

accID=  ApexPages.currentPage().getParameters().get('acId');
public List<OppWrapper> myList = new List<OppWrapper>();

    public PageReference refresh()
        for(Account a : [select id, name, (select name from opportunities) from Account where id= : accID])
            for(Opportunity opp : a.Opportunities)
                myList.add(new OppWrapper(false, opp));
        return null;

    public List<OppWrapper> getMyList()
        return myList;}

  public class OppWrapper {
    public Boolean selected{get;set;}
    public Opportunity opp{get;set;}
    public OppWrapper(Boolean selected1, Opportunity opp1)
        selected = selected1;
        opp = opp1;



vf page -

<apex:page controller="OppControllerr">
<apex:form >
<apex:pageBlock >
<apex:pageBlockSection >
<apex:pageBlockTable id="oppList" value="{!myList}" var="o">
 <apex:column >
        <apex:inputCheckbox value="{!o.selected}" />
<apex:column value="{!o.opp.Name}"/>
<apex:commandButton value="Generate PDF"/>

1 Answer 1


Yes you can achieve it easily using apexCookies here is the sample working code for this

PageReference pg = page.testPdf;
        list<account> accList = [select id, name from account limit 1000];
        string str = '';
        for(account acc : accList){
            str += acc.id + ',';
        Cookie counter = new Cookie('rishi', str ,null,-1,false);
        pg.setCookies(new Cookie[]{counter});
        return pg;

It will have comma seprated ids of account stored in variable rishi

Now in the constructor of your pdf get cookies

str = ApexPages.currentPage().getCookies().get('rishi').getValue();
        list<string> temp = new list<string>();
        temp = str.split(',');
        accList = [select id, name from account where id in : temp ];

Please mark if your query is resolved otherwise let me know your bloackages

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .