You need to sign in to do that
Don't have an account?
VF email template error
Hi I am creating a visual force email template. For this in the email template we require custom objects fields. So I wrote a apex controller and i called the controller in a component. And i called the component inside the VF template. I mentioned the error in red when i am calling the component in the VF template. I hope the error might be because of something missing in Component or in Controller. Can you guys pls have a look at my code and me knoe where did i went wrong. Appreciate your help in advance
Apex Controller
Public Class CAFDetailsController{ Public CAF__c CAF{get;set;} Public String cafid{get;set;} Public List<CAF__c> CAFlist{get;set;} { If (cafid != null) { CAFlist = [Select Id, Name, CAPEX_Total__c, Off_Net_Circuit_Expense_Total__c, CAF_IRR__c, of_Revisions__c, Sales_Rep__c, Sales_Manager__c from CAF__c where Id = :cafId]; } }}
Component
<apex:component controller="CAFDetailsController" access="global">
<apex:attribute name="CAFlist" description="CAF object" type="CAF__c" assignto="{!CAFlist}" />
<apex:outputLabel value="CAFlist" for="CAF__c.CAFId">
<apex:pageBlockSection >
<apex:outputText id="CAPEX" value="{!CAFlist.CAPEX_Total__c}"/>
<apex:outputText id="OffNetCircuitExpense" value="{!CAFlist.Off_Net_Circuit_Expense_Total__c}"/>
<apex:outputText id="SalesManager" value="{!CAFlist.Sales_Manager__c}"/>
</apex:pageBlockSection>
</apex:outputLabel>
</apex:component>
I called the above component in the following way in the VF template and i mentioned the error in red. Can you please let me know where did i do the mistake
VF Template
<c:cafvfdetails CAFlist="{!relatedTo.Id}"/>
Error: Unknown property 'String.CAPEX_Total__c'
the "CAFList" attribute you have defined in your component definition is of type "CAF__c" but in your template you are sending an Id for that attribute... you have to pass a custom object of the correct type. In this case, perhaps you can just send "relatedTo" not "relatedToId". In other words... pass an object, not just an object's Id.
Thanks for the reply. I changed to <c:CAFVFDetails CAFlist="{!relatedTo}"/> as you said. i am able to save the template but after saving i am getting the following error.Can you please let me know waht the below error is and how to resolve?
Error occurred trying to load the template for preview: common.apex.runtime.impl.ExecutionException: Invalid conversion from runtime type SOBJECT:CAF__c to LIST<CAF__c>. Please try editing your markup to correct the problem.
Ah... the component is assigning it to a List of objects not just a single object... basically the original error and this error are similar. You need to make sure your page, component, and controller are all in sync with what type of data the argument will be. They need to be all lists, or all single SObjects.
Hi Now i am able to save the VF template with the following code. But it is acting wiered. When i perform the action submit any record for approval i am not able to receive an email. If i didn't call the component inside the VF template then perform the action i am able to receive the email. But i want the custom object fields in the template so i need to call the component. If i call the component i am not able to receive the email. Here is the controller,component and how did i call the component inside the VF template. Please let me know why i am not able to receive an email when i submit the record. I mentioned in Red at below how i defining the component inside the VF template. If i remove from it from the VF template i am able to receive the basic email
Controller:
Component:
<apex:component controller="CAFDetailsController" access="global">
<apex:attribute name="CAF_id" description="CAF object" type="CAF__c" assignto="{!CAF_id}" />
<apex:dataTable value="{!CAF}" var="CafVar">
<apex:column >
<apex:outputText value="{!CafVar.Sales_Rep__c}" />
</apex:column>
<apex:column >
<apex:outputText value="{!CafVar.Sales_Manager__c}" />
</apex:column>
<apex:column >
<apex:outputText value="{!CafVar.CAPEX_Total__c}" />
</apex:column>
<apex:column >
<apex:outputText value="{!CafVar.Off_Net_Circuit_Expense_Total__c}" />
</apex:column>
<apex:column >
<apex:outputText value="{!CafVar.of_Revisions__c}" />
</apex:column>
<apex:column >
<apex:outputText value="!Cafvar.CAF_Title1_del__c}" />
</apex:column>
<apex:column >
<apex:outputText Value="!CafVar.Products_Requested__c}" />
</apex:column>
<apex:column >
<apex:outputText Value="!CafVar.Bandwidth__c}" />
</apex:column>
</apex:dataTable>
</apex:component>
VF Template: I am calling the above component in the following way
<c:CAFVFDetails CAF_id="{!relatedTo.Id}"/>