1

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.

controller

public class OppControllerr {

Private Id accID;

public OppControllerr(){

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

    public PageReference refresh()
    {
        myList.clear();
        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()
    {
        System.debug('count'+myList.size());
        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>
<apex:column value="{!o.opp.Name}"/>
</apex:pageBlockTable>
</apex:pageBlockSection>
<apex:commandButton value="Generate PDF"/>
</apex:pageBlock>
</apex:form>
</apex:page>

1 Answer 1

0

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 .