To start with
<c:StatementofClaims Contract="{!relatedTo.Id}" policyref="{!relatedTo.Id}" />
doesn't agree with the attribute definitions in the component:
<apex:attribute name="Contract" description="Statement of Claims" type="Contract" />
<apex:attribute name="policyref" description="" type="id" assignTo="{!policyId}" />
You are passing for attribute Contract
the value of {!relatedTo.Id}
which is of type ID but the component is expecting type Contract
You need to do:
<c:StatementofClaims Contract="{!relatedTo}" policyref="{!relatedTo.Id}" />
But, you've made this harder than it has to be:
The preferred pattern is as follows:
<c:StatementofClaims policyref="{!relatedTo.Id}" />
The VF component has a single attribute
<apex:component layout="none" access="global" controller="ClaimsListController2">
<apex:attribute name="policyref" description="" type="id" assignTo="{!policyId}" />
<html>
...
And the VF component controller looks like this
public class ClaimsListController2 {
public Id policyId {get;set;}
public List<Case> claims{
get {
if (claims == null) {
claims = this.policyId == null
? new List<Case>()
: [SELECT Id, CaseNumber, ...
FROM Case WHERE
RecordtypeId = '012b0000000Kr2VAAS' AND
Policy__c = :this.policyId];
return claims;
} private set;
}
public ClaimsListController2() {}
}
Now, you should also avoid hardcoding recordtypeIds in Apex - use the Schema.DescribeSObjectResult.getRecordTypeInfosByDeveloperName()
. See example
Best Answer
I think I have the answer. You cannot pass ideas for Apex:include and you cannot use standard controllers in controllers.
But, you can pass variables from an emailtemplate or Apex Page into a controller. So I create one conmponent with a list of input varaibles (attributes) all of the styling and code is held here:
So within my email, I have:
Here is my visual-force page to allow viewing the receipt in the brow
There is a bit of duplication in specifying the values. But, I think this is a good thing as I could change the values in the receipt dynamically on a per email basis.