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
Sushma Ramakrishnan 5Sushma Ramakrishnan 5 

Getting Error occurred trying to load the template for preview: List has no rows for assignment to SObject. Please try editing your markup to correct the problem. error on Email Template

Hi All,

I am getting the below Error for my Template - VF_Quote Email Template :

Error occurred trying to load the template for preview: List has no rows for assignment to SObject. Please try editing your markup to correct the problem.

Code for VF_Quote Email Template (Visualforce Template):
<messaging:emailTemplate subject="Dear Approver, Quote Number {!relatedTo.QuoteNumber} {!relatedTo.Name} was sent for your approval {!relatedTo.Urgent_Text__c}" recipientType="Contact" relatedToType="Quote">

<messaging:htmlEmailBody >

    <img src="" width="250" height="30"/>

    <meta content="text/html;charset=utf-8" http-equiv="Content-Type"/>
    <meta name="Template" content="Response"/>
    td {
        text-align: right;
        font-family: Verdana;
        text-align: left;
        font-family: Verdana;
    h3 {
        font-family: Verdana;

        <p> <h3><b> Dear Approver, </b> </h3> </p>
        <p> <b> Quote {!relatedTo.QuoteNumber} {!relatedTo.Name} was sent for your approval . <font color="#FF9900"> <apex:outputText value="Urgent" rendered="{!relatedTo.Urgent__c}"/> </font></b> </p>

        <p> <u> <b> Opportunity Owner : </b> </u>  <c:QuoteEmailTemplate2 theQuoteId="{!relatedTo.Id}"/> </p>
        <p> <u> <b> Opportunity Territory : </b> </u>  <c:QuoteEmailTemplate3 theQuoteId="{!relatedTo.Id}"/> </p>
        <p> <u> <b> Account : </b> </u>   {!relatedTo.BillingName} (#{!relatedTo.Account_Number__c })</p>
        <p> <u> <b>Sales Type:</b> </u>  {!relatedTo.bl_Sales_Type__c}   </p>
        <p> <u> <b> Upgrade/Traded : </b> </u>  {!relatedTo.Upgrade_Traded_In_Equipment_Type__c}   </p>
        <p> <u> <b>Comments for Approval : </b> </u>  {!relatedTo.Comments_For_Approval__c}   </p>
        <p> <u> <b> Payment Method </b> </u>: {!relatedTo.Payment_Method__c} <c:QuoteEmailTemplate4 theQuoteId="{!relatedTo.Id}"/> 
         <u> <b> Payment Notes : </b> </u> {!relatedTo.Payment_Notes__c}  </p>
         <p> <u> <b> Payment Notes in English : </b> </u> {!relatedTo.Payment_Note__c}  </p>
          <p> <u> <b>Payment Type : </b> </u>  {!relatedTo.Payment_Type__c }   </p> 
          <p> <u> <b> Special Instructions :</b> </u>  {!relatedTo.Special_Instructions__c}   </p>
          <p> <u> <b> Obligation : </b> </u> {!relatedTo.Obligation__c}   </p>
           <p> <u> <b> Amount for the Obligation : </b> </u> {!relatedTo.Amount_for_the_Obligation__c}   </p>
        <table BORDERCOLOR="blue" style="solid">
                    <th bgcolor="blue"> <font color="#fff"> <b> Product Name</b> </font> </th>
                    <th bgcolor="blue"> <font color="#fff"> <b> Part/KIT Code</b> </font> </th>
                    <th bgcolor="blue"> <font color="#fff"> <b> List Price</b> </font> </th>
                    <th bgcolor="blue"> <font color="#fff"> <b> Quantity</b> </font> </th>
                    <th bgcolor="blue"> <font color="#fff"> <b> Sales Price</b> </font> </th>
                    <th bgcolor="blue"> <font color="#fff"> <b> Total Sales Price</b> </font> </th>
                    <th bgcolor="blue"> <font color="#fff"> <b> Line Discount </b> </font> </th>
                    <th bgcolor="blue"> <font color="#fff"> <b> GM</b> </font> </th>
               <!-- <th bgcolor="blue"> <font color="#fff"> <b> Target Price </b> </font> </th>
                    <th bgcolor="blue"> <font color="#fff"> <b> Discount from Target price </b> </font> </th> -->
                <apex:repeat var="item" value="{!relatedTo.QuoteLineItems}">
                    <td bgcolor="#E2E1E1" text="alignright;"> <p>{!item.Product2.Name} </p> </td>
                    <td bgcolor="#E2E1E1">{!item.Part_KIT_Code__c}</td>  
                    <td bgcolor="#E2E1E1">{!item.VF_Total_Line_List_Price__c}</td>
                    <td bgcolor="#E2E1E1">{!item.Quantity}</td>
                    <td bgcolor="#E2E1E1"> {!item.VF_Sales_Price_After_Discount__c}</td>
                    <td bgcolor="#E2E1E1"> {!item.VF_Total_Sales_Price__c}</td> 
                    <td bgcolor="#E2E1E1">  {!item.Line_Discount_Calculated__c} </td>
                    <td bgcolor="#E2E1E1">  {!item.QLI_Gross_Margin__c} </td>
          <p> <u> <b> Opportunity Currency :</b> </u> {!relatedTo.Opp_Currency__c}   </p>
          <p> <u> <b> Total Deal :</b> </u> {!relatedTo.VF_TotalPrice__c}   </p>   
          <p> <u> <b> Customer Discount :</b> </u> {!relatedTo.Customer_Discount__c}%   </p>   
          <p> <u> <b>  Internal Discount :</b> </u> <c:QuoteEmailTemplate1 theQuoteId="{!relatedTo.Id}"/>*(after target,promotion) </p>

          <p> <u> <b> Gross Margin  :</b> </u>  {!relatedTo.Quote_Gross_Margin__c}%  </p>
          <p> <u> <b> Billing Address : </b> </u> {!relatedTo.BillingStreet}, {!relatedTo.BillingCity}, {!relatedTo.BillingState}, {!relatedTo.BillingCountry}, {!relatedTo.BillingPostalCode}  </p>
          <p> <u> <b> Shipping Address : </b> </u>: {!relatedTo.ShippingStreet}, {!relatedTo.ShippingCity}, {!relatedTo.ShippingState}, {!relatedTo.ShippingCountry}, {!relatedTo.ShippingPostalCode} </p>        
          <p> <u> <b>For further info on the quote </b> </u>: <a href="{!relatedTo.Id}">Link</a> </p>  
          <p> <u> <b> Please approve or reject using one of the following options </b> </u> : </p> 
          <p> <b> 1.  Through the approval request page: </b> </p> <a href=""> Home Page </a>
          <p> <b> 2.   Reply this mail with the one of the following key words: </b> </p>
          <p>  <b>  Approve / Approved / Reject / Rejected / Yes / No </b> </p>
          <p> <b> Thank you,  &nbsp; <c:QuoteEmailTemplateOppOwnerName theQuoteId="{!relatedTo.Id}"/> </b> </p>

The general reason for this error is that the VF email template previewer doesn't have enough information to pass to the component's controller all such information as is typically provided at runtime when you either test the template (by providing a valid ID of the record used in relatedToattribute) or use in APEX or a workflow/process builder.
To solve this and avoid the error message, you need to code the component controller to handle null values for all inputs in a graceful way (that is, assume all inputs can be null - check for null, and handle accordingly without throwing exceptions)
For example - the most likely cause of the NPE is that currentInteractions is null because the setter for it was never invoked. Thus rewrite this method to:
public List<Interactions__c> getAllInteractions() { 
allInteractions = currentInteractions != null ? [Select Id, Name from Interactions__c where Stage__c = 'Open' AND Cutomer__c = :currentInteractions.Customer__c] : new List<Interactions__c>(); return allInteractions; 

Sushma Ramakrishnan 5Sushma Ramakrishnan 5
Hi Subramani,

Thanks for the reply. The below is the Code for the Controller of the Component. Request you to please help me know what changes to be made in the below code :
public class VF_QuoteEmailTemplate {
     public String quoteId {get;set;}
     public ProcessInstanceStep pStep{get;set;}
     public boolean isYellow {get;set;}
     public boolean isGreen {get;set;}
     public boolean isRed {get;set;}
     private String SALES_TYPE_STRAIGHT_SALES = 'Straight Sales';
     private String SALES_TYPE_COMPETATIVE_REPLACEMENT = 'Competitive Replacement';
     private String UPGRADE_TRADE_IN  =  'Upgrade/Trade-In';
      public ProcessInstanceStep getApprovalSteps() {  
      if (quoteId != null) {   
        pStep = new ProcessInstanceStep();   
         try {
            pStep = [Select Comments From ProcessInstanceStep where ProcessInstance.TargetObjectId =: quoteId Limit 1];  
         catch(Exception e) {
      return pStep ;
    public Quote getDiscountFlag() {
        isYellow = false;
        isGreen = false;
        isRed = false;
        Quote theQuote = [SELECT Total_Discount__c, Help_field_for_email_template__c, bl_Sales_Type__c, Discount_from_Target__c FROM Quote WHERE Id =: quoteId];
        if (theQuote != null){
            if (theQuote.bl_Sales_Type__c.EqualsIgnoreCase(SALES_TYPE_STRAIGHT_SALES)
                || theQuote.bl_Sales_Type__c.EqualsIgnoreCase(SALES_TYPE_COMPETATIVE_REPLACEMENT)
                || theQuote.bl_Sales_Type__c.EqualsIgnoreCase(UPGRADE_TRADE_IN)) {
                if(theQuote.Total_Discount__c < 10) {
                    isGreen = true;
                else if( theQuote.Total_Discount__c <= 30 && 10 <= theQuote.Total_Discount__c) {
                    isYellow = true;
                else {
                    isRed = true;
            else {
                if(theQuote.Total_Discount__c == 0) {
                    isGreen = true;
                else if( theQuote.Total_Discount__c <= 15 && 0 <= theQuote.Total_Discount__c) {
                    isYellow = true;
                else {
                    isRed = true;
        return theQuote;
    public Opportunity getOwnerName(){
        Quote theQuote = [SELECT Id, OpportunityId FROM Quote WHERE Id =: quoteId];
        Opportunity relatedOpp;
            relatedOpp = [select Id, Region_Terrirory__c, Owner.Name from Opportunity where Id =: theQuote.OpportunityId];
        return relatedOpp;
    public boolean getQuotePmtMethd() {
        Quote theQuote = [SELECT Id, Payment_Method__c FROM Quote WHERE Id =: quoteId];
        for (QuotePmtMethdFlag__c listCodes : QuotePmtMethdFlag__c.getAll().values() ){
                return false;
        return true;

Thanks for any Help in Advance...! 

check the debug logs and try to get which line number causes for the above error