+ Start a Discussion
TLFTLF 

Having a problem combining {!selected} with renderAs="PDF"

I'm trying to use the "renderAs" attribute, combined with a standard list controller to implement rudimentary mass mail merge capability. I've defined the following VF component:
 
Code:
<apex:component controller="DonationAcknowledgment">
    <apex:attribute name="donationId"
        description="The ID of the donation (Opportunity) to be acknowledged"
        type="String" required="true" assignTo="{!donationId}" />
    Dear {!Contact.Salutation} {!Contact.FirstName} {!Contact.LastName}, <br />
    <br />
    {!Organization.Name} would like to thank you for you generous
    donation of&nbsp;<apex:outputField value="{!Donation.Amount}" />. This email serves as your receipt
    for income tax reporting purposes. Please note that no goods or
    services have been provided in return for this donation. <br />
    <br />
    Sincerely, <br />
    {!User.Name} <br />
    {!User.Title} <br />
    {!User.CompanyName} <br />
    {!User.Street} <br />
    {!User.City} {!User.State} {!User.PostalCode} <br />
    Phone: {!User.Phone} <br />
    Email: {!User.Email}
</apex:component>

And the associated controller:
 
Code:
/* This class provides access to merge fields used to generate a donation acknowledgment letter */
public class DonationAcknowledgment {

    Opportunity o = null;
    Contact c = null;
    Account a = null;
    User u = null;
    Organization org = null;

    String donationId = null;
    
    public DonationAcknowledgment() { 
     System.debug('DonationAcknowledgment constructor called');
    }
    
    public String getDonationId() {
        return this.donationId;
    }
    
    public void setDonationId(String donationId) {
        System.debug('setDonation(' + donationId + ')');
        this.donationId = donationId;
    }

    /* Gets the Donation (Opportunity) object corresponding to the donation ID value */
    public Opportunity getDonation() {
     if (o == null) {
         o = [Select o.OwnerId, o.Name, o.IsClosed, o.Id, o.Description, o.CloseDate, o.Amount, o.AccountId,
            (Select ContactId, Role, IsPrimary From OpportunityContactRoles) 
            From Opportunity o Where o.Id = :donationId Limit 1];
     }
     System.debug('getDonation returning ' + o);
        return o;
    }
    
    public Contact getContact() {
     if (c == null) {
         Opportunity o = getDonation();
         String cId = o.OpportunityContactRoles[0].ContactId;
         c = [Select c.Title, c.Salutation, c.Phone, c.Name, c.MailingStreet, c.MailingState, c.MailingPostalCode,
            c.MailingCountry, c.MailingCity, c.LastName, c.Id, c.HomePhone, c.FirstName, c.Email, c.Description 
            From Contact c Where c.Id = :cId Limit 1];
     }
        return c;
    }
    
    public Account getAccount() {
     if (a == null) {
      Opportunity o = getDonation();
      String aId = o.AccountId;
      a = [Select a.Name, a.Id, a.BillingStreet, a.BillingState, a.BillingPostalCode, a.BillingCountry, a.BillingCity 
                From Account a Where a.Id = :aId Limit 1];
     }
     return a;
    }
    
    public Organization getOrganization() {
     if (org == null) {
      org = [Select o.Street, o.State, o.PrimaryContact, o.PostalCode, o.Phone, o.OrganizationType, 
        o.Name, o.Id, o.Fax, o.Division, o.Country, o.City From Organization o Limit 1];
     }
        return org;
    }
    
    public User getUser() {
     if (u == null) {
         String userId = UserInfo.getUserId();
         u = [Select u.Title, u.Street, u.State, u.PostalCode, u.Phone, u.Name, u.LastName, u.Id, u.FirstName, 
            u.Fax, u.Extension, u.EmployeeNumber, u.Email, u.Division, u.Country, u.CompanyName, u.City 
            From User u Where u.Id = :userId Limit 1];
     }
        return u;
    }
}

 
I then defined a VF page that uses the standard list controller for Opportunity objects as follows:
 
 
Code:
<apex:page standardController="Opportunity" recordSetVar="donations" renderAs="pdf" >
    <apex:repeat value="{!donations}" var="donation">
        <div style="page-break-after: always;">
            <c:donationAcknowledgment donationId="{!donation.Id}" />
        </div>
    </apex:repeat>
</apex:page>

 
This generates a multi-page PDF rendition, with each page populated with merge data, exactly the way I want it. The only issue is that this includes all Opportunity objects returned by the most recent view. What I really want to do is allow the user to select specific Opportunites. So, I modified my VF page as follows:
 
Code:
<apex:page standardController="Opportunity" recordSetVar="donations" renderAs="pdf" >
    <apex:repeat value="{!selected}" var="donation">
        <div style="page-break-after: always;">
            <c:donationAcknowledgment donationId="{!donation.Id}" />
        </div>
    </apex:repeat>
</apex:page>

 
I then created a custom list button and added it to the Opportunities list view. Now, when I try to generate the PDF rendition for several selected Opportunity objects, I get a blank PDF. For debugging purposes, I removed the renderAs attribute so my page would be rendered as HTML, and the page looks correct (meaning only the selected Opportunity objects were merged into the resulting HTML). Any ideas why the use of "{!selected}" is not when combined with renderAs="pdf"? Thanks in advance.
 
TLFTLF
Just to simplify this problem to it's most basic form, I created the following page:
 
Code:
<apex:page standardController="Opportunity" recordSetVar="opps" renderAs="PDF" >
    <apex:repeat value="{!opps}" var="opp">
        <div>
        Opportunity name:&nbsp;{!opp.Name} 
        </br>
        Opportunity amount:&nbsp;<apex:outputField value="{!opp.Amount}" />
        </div>
    </apex:repeat>
</apex:page>

 
This correctly renders the name and amount of all Opportunity objects as PDF. But if I change it to this and select one or more Opportunity objects, the resulting PDF is blank:
 
Code:
<apex:page standardController="Opportunity" recordSetVar="opps" renderAs="PDF" >
    <apex:repeat value="{!selected}" var="opp">
        <div>
        Opportunity name:&nbsp;{!opp.Name} 
        </br>
        Opportunity amount:&nbsp;<apex:outputField value="{!opp.Amount}" />
        </div>
    </apex:repeat>
</apex:page>

 
And if I remove the "renderAs" attribute, the page correctly renders the names and amounts of only the selected Opportunities. Seems like a bug here, unless I'm missing something obvious.
 
 
withoutmewithoutme

Hey,

did you figure out how to accomplish this? I'm helping a non-profit with there customization and have the same requirement. i'm stuck at how to make the renderas = pdf use the !selected method to generate multiple letters.