You need to sign in to do that
Don't have an account?

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%"> </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> <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> <apex:OutputField value="{!Opportunity.npe01__Payments_Made__c}"/></font></td>
<td bgcolor="#C0C0C0" align="right" colspan="4">
<font face="Arial"><b>Balance:</b> <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?
public CustomInv() {
}
Regards,
Mahesh
If I create an empty Constructor it gives the error Unknown property 'CustomInv.Opportunity'
Hi,
VF CodeYou 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.
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
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>
Please find the below code:
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
It still gives the same error List has no rows for assignment to SObject. I suppose it gives the error beacuase of the line:
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
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.
I tested it in my Org and identified the issue.
Please check the below code:
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
Regards,
Mahesh
Please do let me know if you are testing it.
Regards,
Mahesh
If you change it to Opportunity then you have to send the Opportunity SFDC ID.
Regards,
Mahesh
Here is my code again with the updations you suggested :
Controller:
VF Component
vf email template:
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];
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
Here is the Debug Log:
Can you try option in the above by hardcoding, to see whether it is working or not.
<c:CustComp opporId="00640000009LODd"/>
Regards,
Mahesh
cuss?
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
I also gave this hard coded value for OppId in the code:
on testing it shows the OppId To be tmpVar11 :
How does it take tmpVar11 instead of 0067A000002QZjD
Also paste the debug messages here.
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:
and here is the debug log:
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.
Change the below code:
public with sharing class CustomInv
to
public class CustomInv
Regards,
Mahesh
Regards,
Mahesh
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 So opp is not a null value then.