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
LaurenP6777LaurenP6777 

Test Code for Visualforce Email Component Controller

Hi guys, 

I can't seem to get anywhere with the test code for this simple table I put within a Visualforce Email Template:

Controller:
public  class GetOpportunityProducts
{
    public Id OpportunityId {get;set;}
      public List<OpportunityLineItem> GetLineItems()
    {
        List<OpportunityLineItem> line;
        line= [SELECT Quantity,Product2.Name,TotalPrice,Net_Value__c,CurrencyISOCODE,UnitPrice FROM OpportunityLineItem WHERE OpportunityId=: OpportunityId];
        return line;
    }
}
Small Table within VS Email
 
<c:DisplayOppLineItems OppId="{!relatedTo.Id}" /><br/><br/>          
        <br/>


 
Best Answer chosen by LaurenP6777
Prateek Singh SengarPrateek Singh Sengar
@isTest
public class testCustomEmail
{

@isTest
public static void testEmailComp()
{
          //Create dummy product record
          //Create dummy opportunity
          //Create dummy opplineitem

           Test.startTest();
           GetOpportunityProducts obj = new GetOpportunityProducts();
           obj.GetLineItems();
           Test.stopTest();

}

}

Please create dummy test record for product, opportunity and opp line item where the comments is. Hope this helps.