2

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 If I give a constructor with no parameters, it gives the error Unknown property 'CustomInv.Opportunity.

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

3

Your code assumes you are using a StandardController. In other words, it is an extension. Either change your page declaration to:

<apex:page standardController="MyObject__c" extensions="CustomInv">

or add an empty constructor (making it a controller):

public with sharing class CustomInv
{
    public CustomInv()
    {
        // constructor logic.
    }
}
  • I need to use a visualforce component instead of a page as I mentioned earlier this component needs to be added to a visualforce email template. Second adding a empty constructor gives the error Unknown property 'CustomInv.Opportunity – Manya Mahajan Mar 15 '16 at 23:26
  • That means you need the latter option. You need to change Opportunity to opp. You need to pass it in using apex:attribute tags. – Adrian Larson Mar 15 '16 at 23:28

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.