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
SFManiSFMani 

Error: Unknown constructor 'CustomInv.CustomInv()'

I have a custom controller CustomInv. The Code for this is as below: 

public with sharing class CustomInv {
        public Opportunity opp{get;set;}
    
        public  List<npe01__OppPayment__c>  Rec {get; set;}
        public List<Contact> Contact {get; set;}
        public List<Contact> Contact1 {get; set;}
        public List<Contact> Contact2 {get; set;}
        
        ApexPages.StandardController standrdCntrl;
              
        
        public CustomInv(ApexPages.StandardController cntrl){
             standrdCntrl=cntrl;
             this.opp = (Opportunity) standrdCntrl.getRecord();
              
           Contact = [SELECT Name, AccountId FROM Contact WHERE  AccountId=: opp.AccountId and (Title='Primary_M' or Title='Primary_D')  limit 1] ;
           Contact1 = [SELECT Name, AccountId FROM Contact WHERE  AccountId=: opp.AccountId and (Title='Primary_M')  limit 1] ;
           Contact2 = [SELECT Name, AccountId FROM Contact WHERE  AccountId=: opp.AccountId and (Title='Primary_D')  limit 1] ;
             Rec =[Select CreatedDate, SystemModstamp,npe01__Payment_Amount__c, npe01__Opportunity__c, npe01__Paid__c, npe01__Scheduled_Date__c FROM npe01__OppPayment__c WHERE npe01__Paid__c = true and  npe01__Opportunity__c = : ApexPages.currentPage().getParameters().get('id') limit 200];
     

}
}

I am using this controller in a Visualforce Component CustComp.vfc with the code:

<apex:component controller="CustomInv" access="global">
    <table border="0" cellspacing="0" cellpadding="0" width="100%" id="table1">
<tr>
    <td>
        <img src='{!URLFOR($Resource.Logo4567687)}' title="logo" />
        
    </td>
    <p align="center"><font face="Arial"><i>{!$Organization.Name}</i></font><br/>
    <font face="Arial"><i>{!$Organization.Street}</i></font><br/>
    <font face="Arial"><i>{!$Organization.City}</i></font>
    <font face="Arial"><i>,{!$Organization.State}</i></font>
    <font face="Arial"><i>{!$Organization.PostalCode}</i></font></p>
    <!--<td  align="right"><font face="Arial" >
    <b>Invoice for {!Opportunity.Account.Name}</b></font><br/>
   </td>-->
   
  
    
</tr>

<hr/>

</table>
<table border="0" cellspacing="0" cellpadding="0" width="100%" id="table1">
<tr>    <td width="65%"><font face="Arial" >
        Federal Tax ID: 27-0580207<br/>
        </font></td> 
        <!--<td width="50%">&nbsp;</td>-->
   <td width="50%"><font face="Arial">Invoice number: <apex:repeat value="{!Opportunity.Invoices__r}" var="line2">
   {!line2.name}</apex:repeat></font><br/>
  
   
   <font face="Arial">Invoice Date: <apex:repeat value="{!Opportunity.Invoices__r}" var="line2">
   {!line2.Invoice_Date__c} </apex:repeat></font></td>
 
   
  
</tr>
</table>

<br/>
<hr/>
<p><b><font face="Arial" color="#000080">Account Information</font></b></p>

<table border="0" width="100%" id="table2">
<tr>
       <td colspan="3">
           <font face="Arial">Child name: {!Opportunity.Account.Name} <br/><br/></font>
       </td>
</tr>
Parent Name:
<!--<apex:dataList value="{!Contact}" var="con">

<tr>
       <td>          
           <font face="Arial"> {!con.Name}<br/>
                             {!Opportunity.Account.BillingStreet}<br/>
                             {!Opportunity.Account.BillingPostalCode} {!Opportunity.Account.BillingCity}
           </font>
        </td>
        
</tr> 
 </apex:dataList> -->
<!-- <apex:repeat value="{!Contact}" var="con">-->

<apex:repeat value="{!Contact1}" var="con1">

<apex:repeat value="{!Contact2}" var="con2">
<tr>
       <td colspan="3">          
           <font face="Arial"> {!IF(((Opportunity.Description=='Mother')||(Opportunity.Description=='mother')||(Opportunity.Description=='Mom')||(Opportunity.Description=='mom')),con1.Name,IF((Opportunity.Description=='Father')||(Opportunity.Description=='father')||(Opportunity.Description=='Dad')||(Opportunity.Description=='dad'),con2.Name, 'con.Name'))}<br/>
                            
                             {!Opportunity.Account.BillingStreet}<br/>
                             {!Opportunity.Account.BillingPostalCode} {!Opportunity.Account.BillingCity}
           </font>
        </td>
        
</tr> 

</apex:repeat>
</apex:repeat>

</table>
<br/>
<hr/>
<p><b><font color="#000080" face="Arial">Invoice Detail</font></b></p>
<table border="0" width="100%" id="table4">
<tr>
    <td bgcolor="#C0C0C0"><font face="Arial">Item</font></td>
    <td bgcolor="#C0C0C0"><font face="Arial">Description</font></td>
    <td bgcolor="#C0C0C0"><font face="Arial">List Price</font></td>
    <td bgcolor="#C0C0C0"><font face="Arial">Qty</font></td>
    <td bgcolor="#C0C0C0"><font face="Arial">Total Price</font></td>
</tr>

<tr>
       <apex:repeat value="{!Opportunity.OpportunityLineItems}" var="line">
       
          <tr>
              <td>{!line.PricebookEntry.Name}</td>
              <td>{!line.Description}</td>
              <td>{!line.ListPrice}</td>
              <td>{!line.Quantity}</td>
              <td><apex:OutputField value="{!line.SubTotal_Price__c}"/></td>
          </tr>
       </apex:repeat>
</tr>

<tr>
        
       <td bgcolor="#C0C0C0" align="right" colspan="4">
       <font face="Arial"><b>Total:</b>&nbsp;<apex:OutputField value="{!Opportunity.Total_Amount__c}"/></font></td>
</tr>

</table>
<table border="0" width="100%" id="table4">
<tr>
       <td bgcolor="#C0C0C0"><font face="Arial">Post Date</font></td> 
       <td bgcolor="#C0C0C0"><font face="Arial">Due Date</font></td>        
       <!--<td bgcolor="#C0C0C0"><font face="Arial">Description</font></td>  -->  
       <td bgcolor="#C0C0C0"><font face="Arial">Credit</font></td>
       <!--<td bgcolor="#C0C0C0"><font face="Arial">Debit</font></td>  -->    
</tr>
   <apex:variable value="{!1}" var="rowNum"/>
     <apex:repeat value="{!Rec}" var="Pay">
         <tr>
           
             <td> {!Pay.npe01__Scheduled_Date__c}
             <apex:variable var="rowNum" value="{!rowNum + 1}"  /></td>
             <td>{!Pay.npe01__Scheduled_Date__c}</td>             
             <!--<td>{!line.Description}</td> -->                       
             <td><apex:OutputField value="{!Pay.npe01__Payment_Amount__c}"/></td>
             <!--<apex:variable value="{!Opportunity.Amount}" var="amt"/>
             <apex:variable value="{!Pay.npe01__Payment_Amount__c}" var="pmt"/>
             <td><apex:variable value="{!(amt-pmt)}" var="debit1"/>
             <apex:variable value="{!((-pmt*(rowNum-2))-pmt)}" var="debit2"/>
             
             $<apex:outputText value="{!debit1}"/></td>-->
             
          </tr>
        </apex:repeat>
 
      <tr>
        
       <td bgcolor="#C0C0C0" align="right" colspan="2">
       <font face="Arial"><b>Total Credit:</b>&nbsp;<apex:OutputField value="{!Opportunity.npe01__Payments_Made__c}"/></font></td>
       <td bgcolor="#C0C0C0" align="right" colspan="4">
       <font face="Arial"><b>Balance:</b>&nbsp;<apex:OutputField value="{!Opportunity.Balance_Remaining__c}"/></font></td>
</tr> 
         


</table>
<br/>
<hr/>

<p align="center"><font face="Arial"><i>Copyright {!$Organization.Name}.</i></font></p>
</apex:component>


I need to use this VF Component in a Visualforce  Email Template..

But I get the error Unknown constructor 'CustomInv.CustomInv()' in CustComp.vfc 

I am unable to identify why it gives this error. Can someone please help?
 

Mahesh DMahesh D
Create a Constructor with empty something like below:

public CustomInv() {
}

Regards,
Mahesh
SFManiSFMani
Hi Mahesh

If I create an empty Constructor it gives the error Unknown property 'CustomInv.Opportunity'
Naval Sharma4Naval Sharma4

Hi,

You can't use standard controller in Visualforce components. So if you are using this in VF component then move all the code in empty constructor.

I have updated your code.
 

public with sharing class CustomInv {
        public Opportunity opp{get;set;}
    
        public  List<npe01__OppPayment__c>  Rec {get; set;}
        public List<Contact> Contact {get; set;}
        public List<Contact> Contact1 {get; set;}
        public List<Contact> Contact2 {get; set;}
        
        
        public CustomInv(){
             String oppId = ApexPages.currentPage().getParameters().get('id');
             this.opp = [SELECT Id, AccountId, Account.BillingStreet, Account.BillingPostalCode, Account.BillingCity, Description, npe01__Payments_Made__c, Total_Amount__c, Balance_Remaining__c, Amount, (SELECT PricebookEntry.Name, Description, ListPrice, Quantity, SubTotal_Price__c FROM OpportunityLineItems), (SELECT Id, Name, Invoice_Date__c FROM Invoices__r) FROM Opportunity WHERE Id = : oppId];
              
           Contact = [SELECT Name, AccountId FROM Contact WHERE  AccountId=: opp.AccountId and (Title='Primary_M' or Title='Primary_D')  limit 1] ;
           Contact1 = [SELECT Name, AccountId FROM Contact WHERE  AccountId=: opp.AccountId and (Title='Primary_M')  limit 1] ;
           Contact2 = [SELECT Name, AccountId FROM Contact WHERE  AccountId=: opp.AccountId and (Title='Primary_D')  limit 1] ;
             Rec =[Select CreatedDate, SystemModstamp,npe01__Payment_Amount__c, npe01__Opportunity__c, npe01__Paid__c, npe01__Scheduled_Date__c FROM npe01__OppPayment__c WHERE npe01__Paid__c = true and  npe01__Opportunity__c = : oppId limit 200];
     

}
}
VF Code
<apex:component controller="CustomInv" access="global">
    <table border="0" cellspacing="0" cellpadding="0" width="100%" id="table1">
<tr>
    <td>
        <img src='{!URLFOR($Resource.Logo4567687)}' title="logo" />
        
    </td>
    <p align="center"><font face="Arial"><i>{!$Organization.Name}</i></font><br/>
    <font face="Arial"><i>{!$Organization.Street}</i></font><br/>
    <font face="Arial"><i>{!$Organization.City}</i></font>
    <font face="Arial"><i>,{!$Organization.State}</i></font>
    <font face="Arial"><i>{!$Organization.PostalCode}</i></font></p>
    <!--<td  align="right"><font face="Arial" >
    <b>Invoice for {!opp.Account.Name}</b></font><br/>
   </td>-->
   
  
    
</tr>

<hr/>

</table>
<table border="0" cellspacing="0" cellpadding="0" width="100%" id="table1">
<tr>    <td width="65%"><font face="Arial" >
        Federal Tax ID: 27-0580207<br/>
        </font></td> 
        <!--<td width="50%">&nbsp;</td>-->
   <td width="50%"><font face="Arial">Invoice number: <apex:repeat value="{!opp.Invoices__r}" var="line2">
   {!line2.name}</apex:repeat></font><br/>
  
   
   <font face="Arial">Invoice Date: <apex:repeat value="{!opp.Invoices__r}" var="line2">
   {!line2.Invoice_Date__c} </apex:repeat></font></td>
 
   
  
</tr>
</table>

<br/>
<hr/>
<p><b><font face="Arial" color="#000080">Account Information</font></b></p>

<table border="0" width="100%" id="table2">
<tr>
       <td colspan="3">
           <font face="Arial">Child name: {!opp.Account.Name} <br/><br/></font>
       </td>
</tr>
Parent Name:
<!--<apex:dataList value="{!Contact}" var="con">

<tr>
       <td>          
           <font face="Arial"> {!con.Name}<br/>
                             {!opp.Account.BillingStreet}<br/>
                             {!opp.Account.BillingPostalCode} {!opp.Account.BillingCity}
           </font>
        </td>
        
</tr> 
 </apex:dataList> -->
<!-- <apex:repeat value="{!Contact}" var="con">-->

<apex:repeat value="{!Contact1}" var="con1">

<apex:repeat value="{!Contact2}" var="con2">
<tr>
       <td colspan="3">          
           <font face="Arial"> {!IF(((Opportunity.Description=='Mother')||(Opportunity.Description=='mother')||(Opportunity.Description=='Mom')||(Opportunity.Description=='mom')),con1.Name,IF((Opportunity.Description=='Father')||(Opportunity.Description=='father')||(Opportunity.Description=='Dad')||(Opportunity.Description=='dad'),con2.Name, 'con.Name'))}<br/>
                            
                             {!opp.Account.BillingStreet}<br/>
                             {!opp.Account.BillingPostalCode} {!opp.Account.BillingCity}
           </font>
        </td>
        
</tr> 

</apex:repeat>
</apex:repeat>

</table>
<br/>
<hr/>
<p><b><font color="#000080" face="Arial">Invoice Detail</font></b></p>
<table border="0" width="100%" id="table4">
<tr>
    <td bgcolor="#C0C0C0"><font face="Arial">Item</font></td>
    <td bgcolor="#C0C0C0"><font face="Arial">Description</font></td>
    <td bgcolor="#C0C0C0"><font face="Arial">List Price</font></td>
    <td bgcolor="#C0C0C0"><font face="Arial">Qty</font></td>
    <td bgcolor="#C0C0C0"><font face="Arial">Total Price</font></td>
</tr>

<tr>
       <apex:repeat value="{!opp.OpportunityLineItems}" var="line">
       
          <tr>
              <td>{!line.PricebookEntry.Name}</td>
              <td>{!line.Description}</td>
              <td>{!line.ListPrice}</td>
              <td>{!line.Quantity}</td>
              <td><apex:OutputField value="{!line.SubTotal_Price__c}"/></td>
          </tr>
       </apex:repeat>
</tr>

<tr>
        
       <td bgcolor="#C0C0C0" align="right" colspan="4">
       <font face="Arial"><b>Total:</b>&nbsp;<apex:OutputField value="{!opp.Total_Amount__c}"/></font></td>
</tr>

</table>
<table border="0" width="100%" id="table4">
<tr>
       <td bgcolor="#C0C0C0"><font face="Arial">Post Date</font></td> 
       <td bgcolor="#C0C0C0"><font face="Arial">Due Date</font></td>        
       <!--<td bgcolor="#C0C0C0"><font face="Arial">Description</font></td>  -->  
       <td bgcolor="#C0C0C0"><font face="Arial">Credit</font></td>
       <!--<td bgcolor="#C0C0C0"><font face="Arial">Debit</font></td>  -->    
</tr>
   <apex:variable value="{!1}" var="rowNum"/>
     <apex:repeat value="{!Rec}" var="Pay">
         <tr>
           
             <td> {!Pay.npe01__Scheduled_Date__c}
             <apex:variable var="rowNum" value="{!rowNum + 1}"  /></td>
             <td>{!Pay.npe01__Scheduled_Date__c}</td>             
             <!--<td>{!line.Description}</td> -->                       
             <td><apex:OutputField value="{!Pay.npe01__Payment_Amount__c}"/></td>
             <!--<apex:variable value="{!opp.Amount}" var="amt"/>
             <apex:variable value="{!Pay.npe01__Payment_Amount__c}" var="pmt"/>
             <td><apex:variable value="{!(amt-pmt)}" var="debit1"/>
             <apex:variable value="{!((-pmt*(rowNum-2))-pmt)}" var="debit2"/>
             
             $<apex:outputText value="{!debit1}"/></td>-->
             
          </tr>
        </apex:repeat>
 
      <tr>
        
       <td bgcolor="#C0C0C0" align="right" colspan="2">
       <font face="Arial"><b>Total Credit:</b>&nbsp;<apex:OutputField value="{!opp.npe01__Payments_Made__c}"/></font></td>
       <td bgcolor="#C0C0C0" align="right" colspan="4">
       <font face="Arial"><b>Balance:</b>&nbsp;<apex:OutputField value="{!opp.Balance_Remaining__c}"/></font></td>
</tr> 
         


</table>
<br/>
<hr/>

<p align="center"><font face="Arial"><i>Copyright {!$Organization.Name}.</i></font></p>
</apex:component>

 
SFManiSFMani
Updating to your code it now gives the error, List has no rows for assignment to SObject.
Mahesh DMahesh D
Hi Mani,

At what line you got the error?
How are you testing it? You have to pass the id to this component and that should be opportunity id.

Regards,
Mahesh
SFManiSFMani

I am using the vf component in vf email template. when I save the controller class and the vf component it does not give me any error but when I save the vf email template it gives the error List has no rows for assignment to SObject. and it does not mention any row. The code for my VF email template is :

<messaging:emailTemplate subject="Your requested invoice" recipientType="Contact"  
relatedToType="Opportunity">
<messaging:htmlEmailBody >
<table border="0" cellspacing="0" cellpadding="0" width="100%" id="table1">
<td>
Dear {!recipient.name},<br/>
        
        Following your order, please see attached and below your invoice per your request.<br/>
        
        Feel free to contact me if you have any questions.<br/>
        
        Regards,<br/>
        {!$User.FirstName} {!$User.LastName}<br/>
</td>
</table>
<br/>

<c:CustComp />
</messaging:htmlEmailBody>


</messaging:emailTemplate>

Mahesh DMahesh D
Hi Mani,

Please find the below code:
 
public with sharing class CustomInv {
	public Opportunity opp{get;set;}

	public  List<npe01__OppPayment__c>  Rec {get; set;}
	public List<Contact> Contact {get; set;}
	public List<Contact> Contact1 {get; set;}
	public List<Contact> Contact2 {get; set;}
	public String oppId {get; set;}
	
	public CustomInv(){
		//String oppId = ApexPages.currentPage().getParameters().get('id');
		this.opp = [SELECT Id, AccountId, Account.BillingStreet, Account.BillingPostalCode, Account.BillingCity, Description, npe01__Payments_Made__c, Total_Amount__c, Balance_Remaining__c, Amount, (SELECT PricebookEntry.Name, Description, ListPrice, Quantity, SubTotal_Price__c FROM OpportunityLineItems), (SELECT Id, Name, Invoice_Date__c FROM Invoices__r) FROM Opportunity WHERE Id = : oppId];
		  
	    Contact = [SELECT Name, AccountId FROM Contact WHERE  AccountId=: opp.AccountId and (Title='Primary_M' or Title='Primary_D')  limit 1] ;
	    Contact1 = [SELECT Name, AccountId FROM Contact WHERE  AccountId=: opp.AccountId and (Title='Primary_M')  limit 1] ;
	    Contact2 = [SELECT Name, AccountId FROM Contact WHERE  AccountId=: opp.AccountId and (Title='Primary_D')  limit 1] ;
		Rec =[Select CreatedDate, SystemModstamp,npe01__Payment_Amount__c, npe01__Opportunity__c, npe01__Paid__c, npe01__Scheduled_Date__c FROM npe01__OppPayment__c WHERE npe01__Paid__c = true and  npe01__Opportunity__c = : oppId limit 200];
	}
}
 
<apex:component controller="CustomInv" access="global">
	
<apex:attribute name="oppId" description="Attribute on the component." type="String" required="required" assignTo="{!oppId}"/> 
    <table border="0" cellspacing="0" cellpadding="0" width="100%" id="table1">
<tr>
    <td>
        <img src='{!URLFOR($Resource.Logo4567687)}' title="logo" />
        
    </td>
    <p align="center"><font face="Arial"><i>{!$Organization.Name}</i></font><br/>
    <font face="Arial"><i>{!$Organization.Street}</i></font><br/>
    <font face="Arial"><i>{!$Organization.City}</i></font>
    <font face="Arial"><i>,{!$Organization.State}</i></font>
    <font face="Arial"><i>{!$Organization.PostalCode}</i></font></p>
    <!--<td  align="right"><font face="Arial" >
    <b>Invoice for {!opp.Account.Name}</b></font><br/>
   </td>-->
   
  
    
</tr>

<hr/>

</table>
<table border="0" cellspacing="0" cellpadding="0" width="100%" id="table1">
<tr>    <td width="65%"><font face="Arial" >
        Federal Tax ID: 27-0580207<br/>
        </font></td> 
        <!--<td width="50%">&nbsp;</td>-->
   <td width="50%"><font face="Arial">Invoice number: <apex:repeat value="{!opp.Invoices__r}" var="line2">
   {!line2.name}</apex:repeat></font><br/>
  
   
   <font face="Arial">Invoice Date: <apex:repeat value="{!opp.Invoices__r}" var="line2">
   {!line2.Invoice_Date__c} </apex:repeat></font></td>
 
   
  
</tr>
</table>

<br/>
<hr/>
<p><b><font face="Arial" color="#000080">Account Information</font></b></p>

<table border="0" width="100%" id="table2">
<tr>
       <td colspan="3">
           <font face="Arial">Child name: {!opp.Account.Name} <br/><br/></font>
       </td>
</tr>
Parent Name:
<!--<apex:dataList value="{!Contact}" var="con">

<tr>
       <td>          
           <font face="Arial"> {!con.Name}<br/>
                             {!opp.Account.BillingStreet}<br/>
                             {!opp.Account.BillingPostalCode} {!opp.Account.BillingCity}
           </font>
        </td>
        
</tr> 
 </apex:dataList> -->
<!-- <apex:repeat value="{!Contact}" var="con">-->

<apex:repeat value="{!Contact1}" var="con1">

<apex:repeat value="{!Contact2}" var="con2">
<tr>
       <td colspan="3">          
           <font face="Arial"> {!IF(((Opportunity.Description=='Mother')||(Opportunity.Description=='mother')||(Opportunity.Description=='Mom')||(Opportunity.Description=='mom')),con1.Name,IF((Opportunity.Description=='Father')||(Opportunity.Description=='father')||(Opportunity.Description=='Dad')||(Opportunity.Description=='dad'),con2.Name, 'con.Name'))}<br/>
                            
                             {!opp.Account.BillingStreet}<br/>
                             {!opp.Account.BillingPostalCode} {!opp.Account.BillingCity}
           </font>
        </td>
        
</tr> 

</apex:repeat>
</apex:repeat>

</table>
<br/>
<hr/>
<p><b><font color="#000080" face="Arial">Invoice Detail</font></b></p>
<table border="0" width="100%" id="table4">
<tr>
    <td bgcolor="#C0C0C0"><font face="Arial">Item</font></td>
    <td bgcolor="#C0C0C0"><font face="Arial">Description</font></td>
    <td bgcolor="#C0C0C0"><font face="Arial">List Price</font></td>
    <td bgcolor="#C0C0C0"><font face="Arial">Qty</font></td>
    <td bgcolor="#C0C0C0"><font face="Arial">Total Price</font></td>
</tr>

<tr>
       <apex:repeat value="{!opp.OpportunityLineItems}" var="line">
       
          <tr>
              <td>{!line.PricebookEntry.Name}</td>
              <td>{!line.Description}</td>
              <td>{!line.ListPrice}</td>
              <td>{!line.Quantity}</td>
              <td><apex:OutputField value="{!line.SubTotal_Price__c}"/></td>
          </tr>
       </apex:repeat>
</tr>

<tr>
        
       <td bgcolor="#C0C0C0" align="right" colspan="4">
       <font face="Arial"><b>Total:</b>&nbsp;<apex:OutputField value="{!opp.Total_Amount__c}"/></font></td>
</tr>

</table>
<table border="0" width="100%" id="table4">
<tr>
       <td bgcolor="#C0C0C0"><font face="Arial">Post Date</font></td> 
       <td bgcolor="#C0C0C0"><font face="Arial">Due Date</font></td>        
       <!--<td bgcolor="#C0C0C0"><font face="Arial">Description</font></td>  -->  
       <td bgcolor="#C0C0C0"><font face="Arial">Credit</font></td>
       <!--<td bgcolor="#C0C0C0"><font face="Arial">Debit</font></td>  -->    
</tr>
   <apex:variable value="{!1}" var="rowNum"/>
     <apex:repeat value="{!Rec}" var="Pay">
         <tr>
           
             <td> {!Pay.npe01__Scheduled_Date__c}
             <apex:variable var="rowNum" value="{!rowNum + 1}"  /></td>
             <td>{!Pay.npe01__Scheduled_Date__c}</td>             
             <!--<td>{!line.Description}</td> -->                       
             <td><apex:OutputField value="{!Pay.npe01__Payment_Amount__c}"/></td>
             <!--<apex:variable value="{!opp.Amount}" var="amt"/>
             <apex:variable value="{!Pay.npe01__Payment_Amount__c}" var="pmt"/>
             <td><apex:variable value="{!(amt-pmt)}" var="debit1"/>
             <apex:variable value="{!((-pmt*(rowNum-2))-pmt)}" var="debit2"/>
             
             $<apex:outputText value="{!debit1}"/></td>-->
             
          </tr>
        </apex:repeat>
 
      <tr>
        
       <td bgcolor="#C0C0C0" align="right" colspan="2">
       <font face="Arial"><b>Total Credit:</b>&nbsp;<apex:OutputField value="{!opp.npe01__Payments_Made__c}"/></font></td>
       <td bgcolor="#C0C0C0" align="right" colspan="4">
       <font face="Arial"><b>Balance:</b>&nbsp;<apex:OutputField value="{!opp.Balance_Remaining__c}"/></font></td>
</tr> 
         


</table>
<br/>
<hr/>

<p align="center"><font face="Arial"><i>Copyright {!$Organization.Name}.</i></font></p>
</apex:component>
 
<messaging:emailTemplate subject="Your requested invoice" recipientType="Contact"  
relatedToType="Opportunity">
<messaging:htmlEmailBody >
<table border="0" cellspacing="0" cellpadding="0" width="100%" id="table1">
<td>
Dear {!recipient.name},<br/>
        
        Following your order, please see attached and below your invoice per your request.<br/>
        
        Feel free to contact me if you have any questions.<br/>
        
        Regards,<br/>
        {!$User.FirstName} {!$User.LastName}<br/>
</td>
</table>
<br/>

<c:CustComp oppId="00640000009LODd"/>

</messaging:htmlEmailBody>


</messaging:emailTemplate>
In the above code you may need to replace the hard coded opportunity id with dynamic value. Just for testing you can pass any hardcoded value.

Also follow the below link:

https://developer.salesforce.com/docs/atlas.en-us.pages.meta/pages/pages_comp_cust_elements_controllers.htm


Please do let me know if it helps you.

Regards,
Mahesh
SFManiSFMani

It still gives the same error List has no rows for assignment to SObject. I suppose it gives the error beacuase of the line:

this.opp = [SELECT Id, AccountId, Account.BillingStreet, Account.BillingPostalCode, Account.BillingCity, Description, npe01__Payments_Made__c, Total_Amount__c, Balance_Remaining__c, Amount, (SELECT PricebookEntry.Name, Description, ListPrice, Quantity, SubTotal_Price__c FROMOpportunityLineItems), (SELECT Id, Name, Invoice_Date__c FROM Invoices__r) FROM Opportunity WHEREId = : oppId];
Mahesh DMahesh D
Hi Mani,

Yes the error is from the same line and the reason is, whatever the oppId you are passing is empty / null or the record with that id doesn't exists.

Can you add a line before this SOQL like

System.debug('===============oppId:'+oppId);

And paste the debug logs, so that it will be easy to torubleshoot. This will give an idea whether we are getting the oppId id into this controller code or not.

Regards,
Mahesh
SFManiSFMani

I did add the line and here is the debug log:

36.0 APEX_CODE,INFO;APEX_PROFILING,INFO;CALLOUT,INFO;DB,INFO;SYSTEM,DEBUG;VALIDATION,INFO;VISUALFORCE,INFO;WORKFLOW,INFO 11:31:33.0 (81867)|EXECUTION_STARTED 11:31:33.0 (114830)|CODE_UNIT_STARTED|[EXTERNAL]|VisualForce View State 11:31:33.0 (13408106)|CODE_UNIT_FINISHED|VisualForce View State 11:31:33.0 (15235177)|EXECUTION_FINISHED 11:31:33.18 (18267245)|SYSTEM_MODE_ENTER|true

 

I am not sure if this is the correct log we want as I am new to this and can only see this log in the debug logs.

Mahesh DMahesh D
Hi Mani,

I tested it in my Org and identified the issue.

Please check the below code:

 
Public class MyController {
 
    Public Account act {get;set;}
  
    public MyController() {
        getaccount();
    }
    public Account getaccount() {
        act= [Select ID, Name,Description FROM Account Where Id= :ApexPages.CurrentPage().getParameters().get('id')];
        
        if(act.Description != null) {
            if(Pattern.matches('[A-Za-z]{3}[0-9]{3}[a-zA-Z0-9]{3}', act.Description))
                return act;
            else {
              ApexPages.Message myMsg = new ApexPages.Message(ApexPages.Severity.ERROR,'Error: Invalid Input.');
               ApexPages.addMessage(myMsg);
               return Null;
            }
        }
    }
   
    Public PageReference save() {
        update act;
        return Null;
    }
}

Here the issue is with the Description, if the Description is empty then you will get error and if not then you will not get the error.

Now I changed the code to do the pattern check only if the description is having some value.

I tested the code and it is working fine in my DE environment.

Please do let me know if it helps.

Regards,
Mahesh


 
SFManiSFMani
thanks for the code Mahesh. But a Non-void method might not return a value. It gives me this error.
  
Mahesh DMahesh D
Please use the below code:
 
Public class MyController {
 
    Public Account act {get;set;}
  
    public MyController() {
        getaccount();
    }
    public Account getaccount() {
        act= [Select ID, Name,Description FROM Account Where Id= :ApexPages.CurrentPage().getParameters().get('id')];
        
        if(act.Description != null) {
            if(Pattern.matches('[A-Za-z]{3}[0-9]{3}[a-zA-Z0-9]{3}', act.Description))
                return act;
            else {
              ApexPages.Message myMsg = new ApexPages.Message(ApexPages.Severity.ERROR,'Error: Invalid Input.');
               ApexPages.addMessage(myMsg);
            }
        }
		return null;
    }
   
    Public PageReference save() {
        update act;
        return Null;
    }
}

Regards,
Mahesh
SFManiSFMani
:) I used the same code just changing Account to Opportunity, but it gives me the error, Non-void method might not return a value or might have statement after a return statement. Do I need to use the code for Account only?
SFManiSFMani
Just noticed return null was inside if statement. So edited it.
SFManiSFMani
Hi Mahesh, I don't know why but still it isn't working. It is so frustrating. Have tried almost everything. It is giving the same error List has no rows for assignment to SObject.
 
Mahesh DMahesh D
I tested the code and see the below image:

User-added image

Please do let me know if you are testing it.

Regards,
Mahesh
Mahesh DMahesh D
Here the "Id" which you are passing it important, if you pass wrong SFDC ID then you will get the same error.

If you change it to Opportunity then you have to send the Opportunity SFDC ID.

Regards,
Mahesh
SFManiSFMani

Here is my code again with the updations you suggested :

Controller:
 

public with sharing class CustomInv {
    public Opportunity opp{get;set;}
    

    public List<npe01__OppPayment__c>  Rec {get; set;}
    public List<Contact> Contact {get; set;}
    public List<Contact> Contact1 {get; set;}
    public List<Contact> Contact2 {get; set;}
    public String oppId {get; set;}
    
    public CustomInv(){
        getOpp();
         oppId = ApexPages.currentPage().getParameters().get('id');
        System.debug('===============oppId:'+oppId);
        
          
        Contact = [SELECT Name, AccountId FROM Contact WHERE  AccountId=: opp.AccountId and (Title='Primary_M' or Title='Primary_D')  limit 1] ;
        Contact1 = [SELECT Name, AccountId FROM Contact WHERE  AccountId=: opp.AccountId and (Title='Primary_M')  limit 1] ;
        Contact2 = [SELECT Name, AccountId FROM Contact WHERE  AccountId=: opp.AccountId and (Title='Primary_D')  limit 1] ;
        Rec =[Select CreatedDate, SystemModstamp,npe01__Payment_Amount__c, npe01__Opportunity__c, npe01__Paid__c, npe01__Scheduled_Date__c FROM npe01__OppPayment__c WHERE npe01__Paid__c = true and  npe01__Opportunity__c = : oppId limit 200];
    }
    public Opportunity getOpp() {
        
        opp = [SELECT Id, AccountId, Account.BillingStreet, Account.BillingPostalCode, Account.BillingCity, Description, npe01__Payments_Made__c, Total_Amount__c, Balance_Remaining__c, Amount, (SELECT PricebookEntry.Name, Description, ListPrice, Quantity, SubTotal_Price__c FROM OpportunityLineItems), (SELECT Id, Name, Invoice_Date__c FROM Invoices__r) FROM Opportunity WHERE Id= :ApexPages.CurrentPage().getParameters().get('id')];
        if(opp.Description != null) {
            if(Pattern.matches('[A-Za-z]{3}[0-9]{3}[a-zA-Z0-9]{3}', opp.Description))
                return opp;
            else {
              ApexPages.Message myMsg = new ApexPages.Message(ApexPages.Severity.ERROR,'Error: Invalid Input.');
               ApexPages.addMessage(myMsg);
            }
        }
        return null;
    }
   
    Public PageReference save() {
        update opp;
        return Null;
    }
    
}

VF Component
 

<apex:component controller="CustomInv" access="global">
    <apex:attribute name="opporId" description="Attribute on the component." type="String" required="false" assignTo="{!oppId}"/> 
    <table border="0" cellspacing="0" cellpadding="0" width="100%" id="table1">
<tr>
    <td>
        <img src='{!URLFOR($Resource.Logo4567687)}' title="logo" />
        
    </td>
    <p align="center"><font face="Arial"><i>{!$Organization.Name}</i></font><br/>
    <font face="Arial"><i>{!$Organization.Street}</i></font><br/>
    <font face="Arial"><i>{!$Organization.City}</i></font>
    <font face="Arial"><i>,{!$Organization.State}</i></font>
    <font face="Arial"><i>{!$Organization.PostalCode}</i></font></p>
    <!--<td  align="right"><font face="Arial" >
    <b>Invoice for {!opp.Account.Name}</b></font><br/>
   </td>-->
   
  
    
</tr>

<hr/>

</table>
<table border="0" cellspacing="0" cellpadding="0" width="100%" id="table1">
<tr>    <td width="65%"><font face="Arial" >
        Federal Tax ID: 27-0580207<br/>
        </font></td> 
        <!--<td width="50%">&nbsp;</td>-->
   <td width="50%"><font face="Arial">Invoice number: <apex:repeat value="{!opp.Invoices__r}" var="line2">
   {!line2.name}</apex:repeat></font><br/>
  
   
   <font face="Arial">Invoice Date: <apex:repeat value="{!opp.Invoices__r}" var="line2">
   {!line2.Invoice_Date__c} </apex:repeat></font></td>
 
   
  
</tr>
</table>

<br/>
<hr/>
<p><b><font face="Arial" color="#000080">Account Information</font></b></p>

<table border="0" width="100%" id="table2">
<tr>
       <td colspan="3">
           <font face="Arial">Child name: {!opp.Account.Name} <br/><br/></font>
       </td>
</tr>
Parent Name:
<!--<apex:dataList value="{!Contact}" var="con">

<tr>
       <td>          
           <font face="Arial"> {!con.Name}<br/>
                             {!opp.Account.BillingStreet}<br/>
                             {!opp.Account.BillingPostalCode} {!opp.Account.BillingCity}
           </font>
        </td>
        
</tr> 
 </apex:dataList> -->
<!-- <apex:repeat value="{!Contact}" var="con">-->

<apex:repeat value="{!Contact1}" var="con1">

<apex:repeat value="{!Contact2}" var="con2">
<tr>
       <td colspan="3">          
           <font face="Arial"> {!IF(((opp.Description=='Mother')||(opp.Description=='mother')||(opp.Description=='Mom')||(opp.Description=='mom')),con1.Name,IF((opp.Description=='Father')||(opp.Description=='father')||(opp.Description=='Dad')||(opp.Description=='dad'),con2.Name, 'con.Name'))}<br/>
                            
                             {!opp.Account.BillingStreet}<br/>
                             {!opp.Account.BillingPostalCode} {!opp.Account.BillingCity}
           </font>
        </td>
        
</tr> 

</apex:repeat>
</apex:repeat>

</table>
<br/>
<hr/>
<p><b><font color="#000080" face="Arial">Invoice Detail</font></b></p>
<table border="0" width="100%" id="table4">
<tr>
    <td bgcolor="#C0C0C0"><font face="Arial">Item</font></td>
    <td bgcolor="#C0C0C0"><font face="Arial">Description</font></td>
    <td bgcolor="#C0C0C0"><font face="Arial">List Price</font></td>
    <td bgcolor="#C0C0C0"><font face="Arial">Qty</font></td>
    <td bgcolor="#C0C0C0"><font face="Arial">Total Price</font></td>
</tr>

<tr>
       <apex:repeat value="{!opp.opportunityLineItems}" var="line">
       
          <tr>
              <td>{!line.PricebookEntry.Name}</td>
              <td>{!line.Description}</td>
              <td>{!line.ListPrice}</td>
              <td>{!line.Quantity}</td>
              <td><apex:OutputField value="{!line.SubTotal_Price__c}"/></td>
          </tr>
       </apex:repeat>
</tr>

<tr>
        
       <td bgcolor="#C0C0C0" align="right" colspan="4">
       <font face="Arial"><b>Total:</b>&nbsp;<apex:OutputField value="{!opp.Total_Amount__c}"/></font></td>
</tr>

</table>
<table border="0" width="100%" id="table4">
<tr>
       <td bgcolor="#C0C0C0"><font face="Arial">Post Date</font></td> 
       <td bgcolor="#C0C0C0"><font face="Arial">Due Date</font></td>        
       <!--<td bgcolor="#C0C0C0"><font face="Arial">Description</font></td>  -->  
       <td bgcolor="#C0C0C0"><font face="Arial">Credit</font></td>
       <!--<td bgcolor="#C0C0C0"><font face="Arial">Debit</font></td>  -->    
</tr>
   <apex:variable value="{!1}" var="rowNum"/>
     <apex:repeat value="{!Rec}" var="Pay">
         <tr>
           
             <td> {!Pay.npe01__Scheduled_Date__c}
             <apex:variable var="rowNum" value="{!rowNum + 1}"  /></td>
             <td>{!Pay.npe01__Scheduled_Date__c}</td>             
             <!--<td>{!line.Description}</td> -->                       
             <td><apex:OutputField value="{!Pay.npe01__Payment_Amount__c}"/></td>
             <!--<apex:variable value="{!opp.Amount}" var="amt"/>
             <apex:variable value="{!Pay.npe01__Payment_Amount__c}" var="pmt"/>
             <td><apex:variable value="{!(amt-pmt)}" var="debit1"/>
             <apex:variable value="{!((-pmt*(rowNum-2))-pmt)}" var="debit2"/>
             
             $<apex:outputText value="{!debit1}"/></td>-->
             
          </tr>
        </apex:repeat>
 
      <tr>
        
       <td bgcolor="#C0C0C0" align="right" colspan="2">
       <font face="Arial"><b>Total Credit:</b>&nbsp;<apex:OutputField value="{!opp.npe01__Payments_Made__c}"/></font></td>
       <td bgcolor="#C0C0C0" align="right" colspan="4">
       <font face="Arial"><b>Balance:</b>&nbsp;<apex:OutputField value="{!opp.Balance_Remaining__c}"/></font></td>
</tr> 
         


</table>
<br/>
<hr/>

<p align="center"><font face="Arial"><i>Copyright {!$Organization.Name}.</i></font></p>
</apex:component>
 

vf email template:
 

<messaging:emailTemplate subject="Your requested invoice" recipientType="Contact"  
relatedToType="Opportunity">
<messaging:htmlEmailBody >
<table border="0" cellspacing="0" cellpadding="0" width="100%" id="table1">
<td>
Dear {!recipient.name},<br/>
        
        Following your order, please see attached and below your invoice per your request.<br/>
        
        Feel free to contact me if you have any questions.<br/>
        
        Regards,<br/>
        {!$User.FirstName} {!$User.LastName}<br/>
</td>
</table>
<br/>

<c:CustComp opporId="{relatedTo.Id}"/>




</messaging:htmlEmailBody>


</messaging:emailTemplate>
Mahesh DMahesh D
Remove this line:

oppId = ApexPages.currentPage().getParameters().get('id');

And also

opp = [SELECT Id, AccountId, Account.BillingStreet, Account.BillingPostalCode, Account.BillingCity, Description, npe01__Payments_Made__c, Total_Amount__c, Balance_Remaining__c, Amount, (SELECT PricebookEntry.Name, Description, ListPrice, Quantity, SubTotal_Price__c FROMOpportunityLineItems), (SELECT Id, Name, Invoice_Date__c FROM Invoices__r) FROM Opportunity WHEREId= :ApexPages.CurrentPage().getParameters().get('id')];

replace it with

opp = [SELECT Id, AccountId, Account.BillingStreet, Account.BillingPostalCode, Account.BillingCity, Description, npe01__Payments_Made__c, Total_Amount__c, Balance_Remaining__c, Amount, (SELECT PricebookEntry.Name, Description, ListPrice, Quantity, SubTotal_Price__c FROMOpportunityLineItems), (SELECT Id, Name, Invoice_Date__c FROM Invoices__r) FROM Opportunity WHEREId= :oppId];
SFManiSFMani
made the changes as you said, but still the same.
Mahesh DMahesh D
Hi

Basically the issue is, it is not sending the Opportunity Id to the Component's Controller.

Enable the debug and paste the debug here

Option 1:

Hardcode the Opportunity Id and see the results:

<c:CustComp opporId="00640000009LODd"/>  

Option 2:

public CustomInv(){
            System.debug('===============oppId:'+oppId);
            getOpp();
Try to write like above and send me the debugs.

Regards,
Mahesh
      
SFManiSFMani
Can you please share your email ID?
SFManiSFMani
Hello Mahesh,
Here is the Debug Log:
36.0 APEX_CODE,DEBUG;APEX_PROFILING,INFO;CALLOUT,INFO;DB,INFO;SYSTEM,DEBUG;VALIDATION,INFO;VISUALFORCE,INFO;WORKFLOW,INFO
17:11:43.0 (447905)|EXECUTION_STARTED
17:11:43.0 (516369)|CODE_UNIT_STARTED|[EXTERNAL]|01p7A0000000Jtu|CustomInvTest.test
17:11:43.0 (2474917)|SYSTEM_MODE_ENTER|false
17:11:43.0 (2485451)|SYSTEM_MODE_EXIT|false
17:11:43.0 (2727583)|SYSTEM_MODE_ENTER|false
17:11:43.0 (2870569)|USER_DEBUG|[12]|DEBUG|===============oppId:null
17:11:43.0 (3907389)|SOQL_EXECUTE_BEGIN|[25]|Aggregations:2|SELECT Id, AccountId, Account.BillingStreet, Account.BillingPostalCode, Account.BillingCity, Description, npe01__Payments_Made__c, Total_Amount__c, Balance_Remaining__c, Amount, (SELECT PricebookEntry.Name, Description, ListPrice, Quantity, SubTotal_Price__c FROM OpportunityLineItems), (SELECT Id, Name, Invoice_Date__c FROM Invoices__r) FROM Opportunity WHERE Id = :tmpVar1
17:11:43.0 (11059550)|SOQL_EXECUTE_END|[25]|Rows:0
17:11:43.0 (11263199)|SYSTEM_MODE_EXIT|false
17:11:43.0 (11377186)|FATAL_ERROR|System.QueryException: List has no rows for assignment to SObject

Class.CustomInv.getOpp: line 25, column 1
Class.CustomInv.<init>: line 13, column 1
Class.CustomInvTest.test: line 8, column 1
17:11:43.0 (11391963)|FATAL_ERROR|System.QueryException: List has no rows for assignment to SObject

Class.CustomInv.getOpp: line 25, column 1
Class.CustomInv.<init>: line 13, column 1
Class.CustomInvTest.test: line 8, column 1
17:11:43.11 (11400927)|CUMULATIVE_LIMIT_USAGE
17:11:43.11 (11400927)|LIMIT_USAGE_FOR_NS|(default)|
  Number of SOQL queries: 1 out of 100
  Number of query rows: 0 out of 50000
  Number of SOSL queries: 0 out of 20
  Number of DML statements: 0 out of 150
  Number of DML rows: 0 out of 10000
  Maximum CPU time: 0 out of 10000
  Maximum heap size: 0 out of 6000000
  Number of callouts: 0 out of 100
  Number of Email Invocations: 0 out of 10
  Number of future calls: 0 out of 50
  Number of queueable jobs added to the queue: 0 out of 50
  Number of Mobile Apex push calls: 0 out of 10

17:11:43.11 (11400927)|CUMULATIVE_LIMIT_USAGE_END

17:11:43.0 (11440201)|CODE_UNIT_FINISHED|CustomInvTest.test
17:11:43.0 (13082060)|EXECUTION_FINISHED

 
Mahesh DMahesh D
Here oppId is going as null.

Can you try option in the above by hardcoding, to see whether it is working or not.

<c:CustComp opporId="00640000009LODd"/>

Regards,
Mahesh
SFManiSFMani
it still gives this error
 
SFManiSFMani
Can you please share your contact no. or the email id. So it would be easy for me to dis
cuss?
Mahesh DMahesh D
Did you change it the Opp Id from your odg right?

The one which I gave is not the right opp Id.

<c:CustComp opporId="00640000009LODd"/>

Here you have to replace with your orgs opportunity id.

Regards,
Mahesh
SFManiSFMani
yes I used my organization's oppid
SFManiSFMani

I also gave this hard coded value for OppId in the code:

public Opportunity getOpp() {
        oppId = '0067A000002QZjD';
        opp = [SELECT Id, AccountId, Account.BillingStreet, Account.BillingPostalCode, Account.BillingCity, Description, npe01__Payments_Made__c, Total_Amount__c, Balance_Remaining__c, Amount, (SELECT PricebookEntry.Name, Description, ListPrice, Quantity, SubTotal_Price__c FROM OpportunityLineItems), (SELECT Id, Name, Invoice_Date__c FROM Invoices__r) FROM Opportunity WHERE Id=: '0067A000002QZjD'];
        if(opp.Description != null) {
            if(Pattern.matches('[A-Za-z]{3}[0-9]{3}[a-zA-Z0-9]{3}', opp.Description))
                return opp;
            else {
              ApexPages.Message myMsg = new ApexPages.Message(ApexPages.Severity.ERROR,'Error: Invalid Input.');
               ApexPages.addMessage(myMsg);
            }
        }
		return null;
    }

on testing it shows the OppId To be tmpVar11 
SOQL_EXECUTE_BEGIN|[27]|Aggregations:2|SELECT Id, AccountId, Account.BillingStreet, Account.BillingPostalCode, Account.BillingCity, Description, npe01__Payments_Made__c, Total_Amount__c, Balance_Remaining__c, Amount, (SELECT PricebookEntry.Name, Description, ListPrice, Quantity, SubTotal_Price__c FROM OpportunityLineItems), (SELECT Id, Name, Invoice_Date__c FROM Invoices__r) FROM Opportunity WHERE Id = :tmpVar11

How does it take tmpVar11  instead of 0067A000002QZjD
Mahesh DMahesh D
Yes thats how it will display and what was the result.

Also paste the debug messages here.
SFManiSFMani
Here's the debug log: 
36.0 APEX_CODE,DEBUG;APEX_PROFILING,INFO;CALLOUT,INFO;DB,INFO;SYSTEM,DEBUG;VALIDATION,INFO;VISUALFORCE,INFO;WORKFLOW,INFO
20:14:49.0 (528800)|EXECUTION_STARTED
20:14:49.0 (585299)|CODE_UNIT_STARTED|[EXTERNAL]|01p7A0000000Jtu|CustomInvTest.test
20:14:49.0 (2671065)|SYSTEM_MODE_ENTER|false
20:14:49.0 (2681358)|SYSTEM_MODE_EXIT|false
20:14:49.0 (2931563)|SYSTEM_MODE_ENTER|false
20:14:49.0 (3112088)|USER_DEBUG|[14]|DEBUG|===============oppId:0067A000002QZjD
20:14:49.0 (4132579)|SOQL_EXECUTE_BEGIN|[27]|Aggregations:2|SELECT Id, AccountId, Account.BillingStreet, Account.BillingPostalCode, Account.BillingCity, Description, npe01__Payments_Made__c, Total_Amount__c, Balance_Remaining__c, Amount, (SELECT PricebookEntry.Name, Description, ListPrice, Quantity, SubTotal_Price__c FROM OpportunityLineItems), (SELECT Id, Name, Invoice_Date__c FROM Invoices__r) FROM Opportunity WHERE Id = :tmpVar1
20:14:49.0 (7414143)|SOQL_EXECUTE_END|[27]|Rows:0
20:14:49.0 (7621868)|SYSTEM_MODE_EXIT|false
20:14:49.0 (7710904)|FATAL_ERROR|System.QueryException: List has no rows for assignment to SObject

Class.CustomInv.getOpp: line 27, column 1
Class.CustomInv.<init>: line 15, column 1
Class.CustomInvTest.test: line 8, column 1
20:14:49.0 (7725893)|FATAL_ERROR|System.QueryException: List has no rows for assignment to SObject

Class.CustomInv.getOpp: line 27, column 1
Class.CustomInv.<init>: line 15, column 1
Class.CustomInvTest.test: line 8, column 1
20:14:49.7 (7734548)|CUMULATIVE_LIMIT_USAGE
20:14:49.7 (7734548)|LIMIT_USAGE_FOR_NS|(default)|
  Number of SOQL queries: 1 out of 100
  Number of query rows: 0 out of 50000
  Number of SOSL queries: 0 out of 20
  Number of DML statements: 0 out of 150
  Number of DML rows: 0 out of 10000
  Maximum CPU time: 0 out of 10000
  Maximum heap size: 0 out of 6000000
  Number of callouts: 0 out of 100
  Number of Email Invocations: 0 out of 10
  Number of future calls: 0 out of 50
  Number of queueable jobs added to the queue: 0 out of 50
  Number of Mobile Apex push calls: 0 out of 10

20:14:49.7 (7734548)|CUMULATIVE_LIMIT_USAGE_END

20:14:49.0 (7770412)|CODE_UNIT_FINISHED|CustomInvTest.test
20:14:49.0 (9274021)|EXECUTION_FINISHED

 
SFManiSFMani
Hi Mahesh,

I was able to remove the error. I added the query in try catch. But it gives me vf page without any data.
Here is my code for CustomInv:
public with sharing class CustomInv {
	public Opportunity opp{get;set;}
    //ApexPages.StandardController standrdCntrl;
	
	public List<npe01__OppPayment__c>  Rec {get; set;}
	public List<Contact> Contact {get; set;}
	public List<Contact> Contact1 {get; set;}
	public List<Contact> Contact2 {get; set;}
	public String oppId {get; set;}
	
	public CustomInv(){
        // oppId = '0067A000002QZjD';
		
        
        System.debug('===============oppId:'+oppId);
        getOpp();
		
        
		
		  
	    Contact = [SELECT Name, AccountId FROM Contact WHERE  AccountId=: opp.AccountId and (Title='Primary_M' or Title='Primary_D')  limit 1] ;
	    Contact1 = [SELECT Name, AccountId FROM Contact WHERE  AccountId=: opp.AccountId and (Title='Primary_M')  limit 1] ;
	    Contact2 = [SELECT Name, AccountId FROM Contact WHERE  AccountId=: opp.AccountId and (Title='Primary_D')  limit 1] ;
		Rec =[Select CreatedDate, SystemModstamp,npe01__Payment_Amount__c, npe01__Opportunity__c, npe01__Paid__c, npe01__Scheduled_Date__c FROM npe01__OppPayment__c WHERE npe01__Paid__c = true and  npe01__Opportunity__c = : oppId limit 1];
	}
    public Opportunity getOpp() {
        //oppId = '0067A000002QZjD';
        
        try{
           if(opp!=null) 
           {opp = [SELECT Id, AccountId, Account.Name, Account.BillingStreet, Account.BillingPostalCode, Account.BillingCity, Description, npe01__Payments_Made__c, Total_Amount__c, Balance_Remaining__c, Amount, (SELECT PricebookEntry.Name, Description, ListPrice, Quantity, SubTotal_Price__c FROM OpportunityLineItems), (SELECT Id, Name, Invoice_Date__c FROM Invoices__r) FROM Opportunity WHERE Id=: oppId limit 1];
           }else
            {opp=new Opportunity();
             System.debug( 'value='+opp);}
        }
        catch(exception e){
            System.debug(e);
        }
        //System.debug('===============opp Name:'+opp.Name);
        if(opp.Description != null) {
            if(Pattern.matches('[A-Za-z]{3}[0-9]{3}[a-zA-Z0-9]{3}', opp.Description))
                return opp;
            else {
              ApexPages.Message myMsg = new ApexPages.Message(ApexPages.Severity.ERROR,'Error: Invalid Input.');
               ApexPages.addMessage(myMsg);
            }
        }
		return null;
    }
   
    Public PageReference save() {
        update opp;
        return Null;
    }
    
}

and here is the debug log:
36.0 APEX_CODE,DEBUG;APEX_PROFILING,INFO;CALLOUT,INFO;DB,INFO;SYSTEM,DEBUG;VALIDATION,INFO;VISUALFORCE,INFO;WORKFLOW,INFO
22:53:05.0 (441274)|EXECUTION_STARTED
22:53:05.0 (507759)|CODE_UNIT_STARTED|[EXTERNAL]|01p7A0000000Jtu|CustomInvTest.test
22:53:05.0 (2827756)|SYSTEM_MODE_ENTER|false
22:53:05.0 (2837619)|SYSTEM_MODE_EXIT|false
22:53:05.0 (3141210)|SYSTEM_MODE_ENTER|false
22:53:05.0 (3327013)|USER_DEBUG|[15]|DEBUG|===============oppId:null
22:53:05.0 (3733532)|USER_DEBUG|[34]|DEBUG|value=Opportunity:{}
22:53:05.0 (4273866)|SOQL_EXECUTE_BEGIN|[21]|Aggregations:0|SELECT Name, AccountId FROM Contact WHERE (AccountId = :tmpVar1 AND (Title = 'Primary_M' OR Title = 'Primary_D')) LIMIT 1
22:53:05.0 (6127143)|SOQL_EXECUTE_END|[21]|Rows:0
22:53:05.0 (6460197)|SOQL_EXECUTE_BEGIN|[22]|Aggregations:0|SELECT Name, AccountId FROM Contact WHERE (AccountId = :tmpVar1 AND Title = 'Primary_M') LIMIT 1
22:53:05.0 (7815861)|SOQL_EXECUTE_END|[22]|Rows:0
22:53:05.0 (8145241)|SOQL_EXECUTE_BEGIN|[23]|Aggregations:0|SELECT Name, AccountId FROM Contact WHERE (AccountId = :tmpVar1 AND Title = 'Primary_D') LIMIT 1
22:53:05.0 (9409003)|SOQL_EXECUTE_END|[23]|Rows:0
22:53:05.0 (10741720)|SOQL_EXECUTE_BEGIN|[24]|Aggregations:0|SELECT CreatedDate, SystemModstamp, npe01__Payment_Amount__c, npe01__Opportunity__c, npe01__Paid__c, npe01__Scheduled_Date__c FROM npe01__OppPayment__c WHERE (npe01__Paid__c = TRUE AND npe01__Opportunity__c = :tmpVar1) LIMIT 1
22:53:05.0 (12673537)|SOQL_EXECUTE_END|[24]|Rows:0
22:53:05.0 (12754151)|SYSTEM_MODE_EXIT|false
22:53:05.0 (15896222)|SYSTEM_MODE_ENTER|false
22:53:05.0 (17191885)|SOQL_EXECUTE_BEGIN|[31]|Aggregations:2|SELECT Id, AccountId, Account.Name, Account.BillingStreet, Account.BillingPostalCode, Account.BillingCity, Description, npe01__Payments_Made__c, Total_Amount__c, Balance_Remaining__c, Amount, (SELECT PricebookEntry.Name, Description, ListPrice, Quantity, SubTotal_Price__c FROM OpportunityLineItems), (SELECT Id, Name, Invoice_Date__c FROM Invoices__r) FROM Opportunity WHERE Id = :tmpVar1 LIMIT 1
22:53:05.0 (20913433)|SOQL_EXECUTE_END|[31]|Rows:0
22:53:05.0 (21221608)|USER_DEBUG|[37]|DEBUG|System.QueryException: List has no rows for assignment to SObject
22:53:05.0 (21246552)|SYSTEM_MODE_EXIT|false
22:53:05.23 (23071970)|CUMULATIVE_LIMIT_USAGE
22:53:05.23 (23071970)|LIMIT_USAGE_FOR_NS|(default)|
  Number of SOQL queries: 4 out of 100
  Number of query rows: 0 out of 50000
  Number of SOSL queries: 0 out of 20
  Number of DML statements: 0 out of 150
  Number of DML rows: 0 out of 10000
  Maximum CPU time: 0 out of 10000
  Maximum heap size: 0 out of 6000000
  Number of callouts: 0 out of 100
  Number of Email Invocations: 0 out of 10
  Number of future calls: 0 out of 50
  Number of queueable jobs added to the queue: 0 out of 50
  Number of Mobile Apex push calls: 0 out of 10

22:53:05.23 (23071970)|TESTING_LIMITS
22:53:05.23 (23071970)|LIMIT_USAGE_FOR_NS|(default)|
  Number of SOQL queries: 1 out of 100
  Number of query rows: 0 out of 50000
  Number of SOSL queries: 0 out of 20
  Number of DML statements: 0 out of 150
  Number of DML rows: 0 out of 10000
  Maximum CPU time: 0 out of 10000
  Maximum heap size: 0 out of 6000000
  Number of callouts: 0 out of 100
  Number of Email Invocations: 0 out of 10
  Number of future calls: 0 out of 50
  Number of queueable jobs added to the queue: 0 out of 50
  Number of Mobile Apex push calls: 0 out of 10

22:53:05.23 (23071970)|CUMULATIVE_LIMIT_USAGE_END

22:53:05.0 (23118970)|CODE_UNIT_FINISHED|CustomInvTest.test
22:53:05.0 (24110501)|EXECUTION_FINISHED

It is taking oppId as null and if I hardcode the oppId, it does show me the vf email template with the correct data. The problem occuring is, it is not taking any value for the oppId.
 
Mahesh DMahesh D
Remove "with sharing" from your class and try by hardcoding the OppId.

Change the below code:

public with sharing class CustomInv

to

public class CustomInv


Regards,
Mahesh
SFManiSFMani
removed "with sharing" and also hard coded oppId, but still no data.
SFManiSFMani
here is the debug now:
36.0 APEX_CODE,DEBUG;APEX_PROFILING,INFO;CALLOUT,INFO;DB,INFO;SYSTEM,DEBUG;VALIDATION,INFO;VISUALFORCE,INFO;WORKFLOW,INFO
13:25:48.0 (278340)|EXECUTION_STARTED
13:25:48.0 (364282)|CODE_UNIT_STARTED|[EXTERNAL]|01p7A0000000Jtu|CustomInvTest.test
13:25:48.0 (2709486)|SYSTEM_MODE_ENTER|false
13:25:48.0 (2719845)|SYSTEM_MODE_EXIT|false
13:25:48.0 (3019594)|SYSTEM_MODE_ENTER|false
13:25:48.0 (3239268)|USER_DEBUG|[15]|DEBUG|===============oppId:0067A000002QZjD
13:25:48.0 (3665234)|USER_DEBUG|[34]|DEBUG|value=Opportunity:{}
13:25:48.0 (4127324)|SOQL_EXECUTE_BEGIN|[21]|Aggregations:0|SELECT Name, AccountId FROM Contact WHERE (AccountId = :tmpVar1 AND (Title = 'Primary_M' OR Title = 'Primary_D')) LIMIT 1
13:25:48.0 (5715286)|SOQL_EXECUTE_END|[21]|Rows:0
13:25:48.0 (6065860)|SOQL_EXECUTE_BEGIN|[22]|Aggregations:0|SELECT Name, AccountId FROM Contact WHERE (AccountId = :tmpVar1 AND Title = 'Primary_M') LIMIT 1
13:25:48.0 (7260335)|SOQL_EXECUTE_END|[22]|Rows:0
13:25:48.0 (7585890)|SOQL_EXECUTE_BEGIN|[23]|Aggregations:0|SELECT Name, AccountId FROM Contact WHERE (AccountId = :tmpVar1 AND Title = 'Primary_D') LIMIT 1
13:25:48.0 (9040232)|SOQL_EXECUTE_END|[23]|Rows:0
13:25:48.0 (10157741)|SOQL_EXECUTE_BEGIN|[24]|Aggregations:0|SELECT CreatedDate, SystemModstamp, npe01__Payment_Amount__c, npe01__Opportunity__c, npe01__Paid__c, npe01__Scheduled_Date__c FROM npe01__OppPayment__c WHERE (npe01__Paid__c = TRUE AND npe01__Opportunity__c = :tmpVar1) LIMIT 1
13:25:48.0 (11975453)|SOQL_EXECUTE_END|[24]|Rows:0
13:25:48.0 (12061596)|SYSTEM_MODE_EXIT|false
13:25:48.0 (15013755)|SYSTEM_MODE_ENTER|false
13:25:48.0 (16050123)|SOQL_EXECUTE_BEGIN|[31]|Aggregations:2|SELECT Id, AccountId, Account.Name, Account.BillingStreet, Account.BillingPostalCode, Account.BillingCity, Description, npe01__Payments_Made__c, Total_Amount__c, Balance_Remaining__c, Amount, (SELECT PricebookEntry.Name, Description, ListPrice, Quantity, SubTotal_Price__c FROM OpportunityLineItems), (SELECT Id, Name, Invoice_Date__c FROM Invoices__r) FROM Opportunity WHERE Id = :tmpVar1
13:25:48.0 (19506617)|SOQL_EXECUTE_END|[31]|Rows:0
13:25:48.0 (19759024)|USER_DEBUG|[37]|DEBUG|System.QueryException: List has no rows for assignment to SObject
13:25:48.0 (19782716)|SYSTEM_MODE_EXIT|false
13:25:48.21 (21535793)|CUMULATIVE_LIMIT_USAGE
13:25:48.21 (21535793)|LIMIT_USAGE_FOR_NS|(default)|
  Number of SOQL queries: 4 out of 100
  Number of query rows: 0 out of 50000
  Number of SOSL queries: 0 out of 20
  Number of DML statements: 0 out of 150
  Number of DML rows: 0 out of 10000
  Maximum CPU time: 0 out of 10000
  Maximum heap size: 0 out of 6000000
  Number of callouts: 0 out of 100
  Number of Email Invocations: 0 out of 10
  Number of future calls: 0 out of 50
  Number of queueable jobs added to the queue: 0 out of 50
  Number of Mobile Apex push calls: 0 out of 10

13:25:48.21 (21535793)|TESTING_LIMITS
13:25:48.21 (21535793)|LIMIT_USAGE_FOR_NS|(default)|
  Number of SOQL queries: 1 out of 100
  Number of query rows: 0 out of 50000
  Number of SOSL queries: 0 out of 20
  Number of DML statements: 0 out of 150
  Number of DML rows: 0 out of 10000
  Maximum CPU time: 0 out of 10000
  Maximum heap size: 0 out of 6000000
  Number of callouts: 0 out of 100
  Number of Email Invocations: 0 out of 10
  Number of future calls: 0 out of 50
  Number of queueable jobs added to the queue: 0 out of 50
  Number of Mobile Apex push calls: 0 out of 10

13:25:48.21 (21535793)|CUMULATIVE_LIMIT_USAGE_END

13:25:48.0 (21593163)|CODE_UNIT_FINISHED|CustomInvTest.test
13:25:48.0 (22585029)|EXECUTION_FINISHED

 
Mahesh DMahesh D
Please try the below code:
 
public class CustomInv {
	public Opportunity opp{get;set;}
    
	//public List<npe01__OppPayment__c>  Rec {get; set;}
	public List<Contact> Contact {get; set;}
	public List<Contact> Contact1 {get; set;}
	public List<Contact> Contact2 {get; set;}
	public String oppId {get; set;}
	
	public CustomInv(){
        // oppId = '0067A000002QZjD';
        
        System.debug('===============oppId:'+oppId);
        getOpp();
		  
	    Contact = [SELECT Name, AccountId FROM Contact WHERE  AccountId=: opp.AccountId and (Title='Primary_M' or Title='Primary_D')  limit 1] ;
	    Contact1 = [SELECT Name, AccountId FROM Contact WHERE  AccountId=: opp.AccountId and (Title='Primary_M')  limit 1] ;
	    Contact2 = [SELECT Name, AccountId FROM Contact WHERE  AccountId=: opp.AccountId and (Title='Primary_D')  limit 1] ;
		//Rec =[Select CreatedDate, SystemModstamp,npe01__Payment_Amount__c, npe01__Opportunity__c, npe01__Paid__c, npe01__Scheduled_Date__c FROM npe01__OppPayment__c WHERE npe01__Paid__c = true and  npe01__Opportunity__c = : oppId limit 1];
	}
    public Opportunity getOpp() {
        //oppId = '0067A000002QZjD';
        
        try{
            if(oppId != null) {
				opp = [SELECT Id, AccountId, Account.Name, Account.BillingStreet, Account.BillingPostalCode, Account.BillingCity, Description, npe01__Payments_Made__c, Total_Amount__c, Balance_Remaining__c, Amount, (SELECT PricebookEntry.Name, Description, ListPrice, Quantity, SubTotal_Price__c FROM OpportunityLineItems), (SELECT Id, Name, Invoice_Date__c FROM Invoices__r) FROM Opportunity WHERE Id=: oppId limit 1];
            } else {
			    opp=new Opportunity();
				System.debug( 'value='+opp);
			}
        }
        catch(exception e){
            System.debug(e);
        }
        //System.debug('===============opp Name:'+opp.Name);
        if(opp.Description != null) {
            if(Pattern.matches('[A-Za-z]{3}[0-9]{3}[a-zA-Z0-9]{3}', opp.Description))
                return opp;
            else {
              ApexPages.Message myMsg = new ApexPages.Message(ApexPages.Severity.ERROR,'Error: Invalid Input.');
               ApexPages.addMessage(myMsg);
            }
        }
		return null;
    }
   
    Public PageReference save() {
        update opp;
        return Null;
    }
}

Regards,
Mahesh
SFManiSFMani
Still the same.
36.0 APEX_CODE,DEBUG;APEX_PROFILING,INFO;CALLOUT,INFO;DB,INFO;SYSTEM,DEBUG;VALIDATION,INFO;VISUALFORCE,INFO;WORKFLOW,INFO
17:06:42.0 (513254)|EXECUTION_STARTED
17:06:42.0 (606672)|CODE_UNIT_STARTED|[EXTERNAL]|01p7A0000000Jtu|CustomInvTest.test
17:06:42.0 (2448244)|USER_DEBUG|[13]|DEBUG|===============oppId:null
17:06:42.0 (2799855)|USER_DEBUG|[29]|DEBUG|value=Opportunity:{}
17:06:42.0 (3219780)|SOQL_EXECUTE_BEGIN|[16]|Aggregations:0|SELECT Name, AccountId FROM Contact WHERE (AccountId = :tmpVar1 AND (Title = 'Primary_M' OR Title = 'Primary_D')) LIMIT 1
17:06:42.0 (9071200)|SOQL_EXECUTE_END|[16]|Rows:0
17:06:42.0 (9396209)|SOQL_EXECUTE_BEGIN|[17]|Aggregations:0|SELECT Name, AccountId FROM Contact WHERE (AccountId = :tmpVar1 AND Title = 'Primary_M') LIMIT 1
17:06:42.0 (12184475)|SOQL_EXECUTE_END|[17]|Rows:0
17:06:42.0 (12484089)|SOQL_EXECUTE_BEGIN|[18]|Aggregations:0|SELECT Name, AccountId FROM Contact WHERE (AccountId = :tmpVar1 AND Title = 'Primary_D') LIMIT 1
17:06:42.0 (14630147)|SOQL_EXECUTE_END|[18]|Rows:0
17:06:42.0 (16839031)|USER_DEBUG|[29]|DEBUG|value=Opportunity:{}
17:06:42.18 (18057241)|CUMULATIVE_LIMIT_USAGE
17:06:42.18 (18057241)|LIMIT_USAGE_FOR_NS|(default)|
  Number of SOQL queries: 3 out of 100
  Number of query rows: 0 out of 50000
  Number of SOSL queries: 0 out of 20
  Number of DML statements: 0 out of 150
  Number of DML rows: 0 out of 10000
  Maximum CPU time: 0 out of 10000
  Maximum heap size: 0 out of 6000000
  Number of callouts: 0 out of 100
  Number of Email Invocations: 0 out of 10
  Number of future calls: 0 out of 50
  Number of queueable jobs added to the queue: 0 out of 50
  Number of Mobile Apex push calls: 0 out of 10

17:06:42.18 (18057241)|TESTING_LIMITS
17:06:42.18 (18057241)|LIMIT_USAGE_FOR_NS|(default)|
  Number of SOQL queries: 0 out of 100
  Number of query rows: 0 out of 50000
  Number of SOSL queries: 0 out of 20
  Number of DML statements: 0 out of 150
  Number of DML rows: 0 out of 10000
  Maximum CPU time: 0 out of 10000
  Maximum heap size: 0 out of 6000000
  Number of callouts: 0 out of 100
  Number of Email Invocations: 0 out of 10
  Number of future calls: 0 out of 50
  Number of queueable jobs added to the queue: 0 out of 50
  Number of Mobile Apex push calls: 0 out of 10

17:06:42.18 (18057241)|CUMULATIVE_LIMIT_USAGE_END

17:06:42.0 (18120976)|CODE_UNIT_FINISHED|CustomInvTest.test
17:06:42.0 (19080443)|EXECUTION_FINISHED

 
SFManiSFMani
It is still taking oppId as null.

I think because we are using a constructor with no parameters, so it doesn't find any Id value corresponding to an opportunity.

I had already created this in visualforce page rendering it as pdf. And there it is working absolutely fine. But now to embedd this in a visualforce email template, this issue is occuring. In VF Page I used Contact and Rec as extensions. I had made 2 different controllers for contacts and Receivables <npe01__OppPayment__c>. There I passed (Apexpages.standardController cntrl) as parameters in the constructors. ANd then gave   
opp = (Opportunity) cntrl.getRecord();
So opp is not a null value then.