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
huskerwendyhuskerwendy 

Visualforce Email template not displaying outputField

I'm writing my first visualforce email template and am having a problem with it not displaying the OutputField. I'm not sure what I'm doing wrong. 

Here's the controller:

public class getBloomerProductsController {
	// get the oppty id
	public id OpptyID {get;set;}

	//a list to hold the bloomerproducts
	public List<OpportunityLineItem> BloomerangProducts {get;set;}
	
	public getBloomerProductsController() {		
	}
	
	public List<OpportunityLineItem> BloomerangProducts() {
		System.debug('bloomerangProducts is' + BloomerangProducts);
		System.debug('OpportunityID is'+ OpptyID);
		return [Select PricebookEntry.Name From OpportunityLineItem WHERE HasBloomerang__c = true and OpportunityID =: OpptyID];		
	}
}

 Here's the component:

<apex:component id="getBloomerProducts" controller="getBloomerProductsController" access="global">	
	<apex:attribute name="OpportunityID" description="This is the Opportunity Id." type="Id" assignTo="{!OpptyID}"/> 
	<table border="1">
		<tr>
		    <td><apex:outputText value="Product name"/></td>
		</tr>  
 	<apex:repeat value="{!BloomerangProducts}" var="blp" >
		<tr>
		    <td><apex:outputField value="{!blp.PricebookEntry.Name}"/></td>		    
		</tr>                
	</apex:repeat>
	</table>
</apex:component>

 Here's the email template

<messaging:emailTemplate recipientType="Contact"
    relatedToType="Opportunity"
    subject="New Firespring Bloomerang Sale"
    replyTo="sales@firespring.com" >
    
<messaging:htmlEmailBody >        
    <html>
        <body>
         <STYLE type="text/css">
               TH {font-size: 11px; font-face: arial;background: #CCCCCC; border-width: 1;  text-align: center } 
               TD  {font-size: 11px; font-face: verdana } 
               TABLE {border: solid #CCCCCC; border-width: 1}
               TR {border: solid #CCCCCC; border-width: 1}
         </STYLE>
        <font face="arial" size="2">
        <p>A new sale was made to:</p>
        <br/>Account:{!relatedTo.Account.name}    
        <br/>Contact:{!recipient.Name}      
        <c:getBloomerProductsController OpportunityID="{!relatedTo.Id}"></c:getBloomerProductsController>
         </font>
       
        </body>
    </html>
</messaging:htmlEmailBody>    
        
</messaging:emailTemplate>

 

I thought maybe I was writing the query incorrectly so I changed the query to select only the OpportunityLineItem.Id and it still doesn't display any products. What am I doing wrong?

 

Thanks!

Best Answer chosen by Admin (Salesforce Developers) 
Kiran  KurellaKiran Kurella

I think you just need to define the variable as Public. 

 

//a list to hold the bloomerproducts
public List<OpportunityLineItem> BloomerangProducts {get; set;}

 

All Answers

Kiran  KurellaKiran Kurella

Can you try replacing the controller code with the following:

 

public class getBloomerProductsController {

	//a list to hold the bloomerproducts
	List<OpportunityLineItem> BloomerangProducts {get; set;}

	// get the oppty id
	public id OpptyID {
	get;
	set {
	     OpptyID = value;
	     BloomerangProducts = [Select PricebookEntry.Name From OpportunityLineItem WHERE HasBloomerang__c = true and OpportunityID =: OpptyID];	
	   }
	}

}

 

huskerwendyhuskerwendy

Thanks for the help Codewizard. I replaced the controller with that code and now I get the error "Error: Unknown property 'getBloomerProductsController.BloomerangProducts"

Kiran  KurellaKiran Kurella

I think you just need to define the variable as Public. 

 

//a list to hold the bloomerproducts
public List<OpportunityLineItem> BloomerangProducts {get; set;}

 

This was selected as the best answer
huskerwendyhuskerwendy

That fixed it. Thanks!