You need to sign in to do that
Don't have an account?
huskerwendy
Test class for Visualforce Email Template
I made my first Visualforce page which is a Visualforce Email Template. I'm having a problem writing a test class with 100% coverage. Currently, I'm at 50% and it's only got to cover four lines. I'm not sure what I'm doing wrong. Here's the test class. I added the create account, opportunity and opportunity line item but it didn't change my code coverage.
@isTest private class TestGetBloomerProductsController { public static testMethod void myUnitTest() { Account a = new Account(Name='Testing Account', Industry='Nonprofit', Type = 'Client'); insert a; Opportunity oppty = new Opportunity( name='wendy test', Type = 'New Client', StageName = 'Close/Won', Reason_Won_Lost__c='Design', CloseDate=System.today(), AccountId=a.id); insert oppty; OpportunityLineItem oli = new OpportunityLineItem( UnitPrice = 0.00, Quantity = 1, PricebookEntryId = [select Id From PricebookEntry Where Name = 'Bloomerang 1,001-5,000 Records' LIMIT 1].id, OpportunityId = oppty.Id); PageReference pageRef = Page.success; Test.setCurrentPage(pageRef); getBloomerProductsController controller = new getBloomerProductsController(); } }
Here's the controller class: (only lines 4 and 7 are covered and I need to cover 10 and 11)
public class getBloomerProductsController { 2 3 //a list to hold the bloomerproducts 4 public List<OpportunityLineItem> BloomerangProducts {get; set;} 5 6 // get the oppty id 7 public id OpptyID { 8 get; 9 set { 10 OpptyID = value; 11 BloomerangProducts = [Select PricebookEntry.Name From OpportunityLineItem WHERE HasBloomerang__c = true and OpportunityID =: OpptyID]; 12 } 13 } 14 }
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}"/> <apex:repeat value="{!BloomerangProducts}" var="blp" > <br> <apex:outputText value="Product: "/><apex:outputField value="{!blp.PricebookEntry.Name}"/> </br> </apex:repeat> </apex:component>
All Answers
controller.setOpptyID (oppty.Id);
Thanks for the reply. When I add that code at the end, I get this error: Save error: Method does not exist or incorrect signature: [getBloomerProductsController].setOpptyID(Id)
That got me to thinking and I changed it to this and it worked.
controller.OpptyID=oppty.id;
Thanks!
We posted at the same time. ;) Thanks so much for the help.