You need to sign in to do that
Don't have an account?
Question about how 'thisContactId' works
I have a master-detail hierarchy that goes: School Implementations-->Teacher Implementations-->Class Implementations. On School Implementations there is a look-up field called "Principal Name" that links to the contact of the school's principal. I would like to send the principal an email that contains several pieces of information about all of the class implementations at the school. Using gokubi's model (http://gokubi.com/archives/visual-force-email-templates-2) I have mostly everything set up correctly, I think. The problem is that my WHERE statement for theWholeList in my Apex controller ends up filtering out ALL results:
theWholeList = [SELECT Id, Name, School_Implementation__r.Name, School_Implementation__r.Principal_Name__c, School_Implementation__r.Id FROM Teacher_Implementation__c WHERE School_Implementation__r.Principal_Name__c = :thisContactId];
When I remove the WHERE statement everything works fine (except for the fact that it gives me all class implementations for EVERY school, of course). Maybe I am misunderstanding how 'thisContactId' works? It doesn't seem to matching up with the recipient.Id in my email template.
Here's all the components:
Visualforce email template:
<messaging:emailTemplate recipientType="Contact" relatedToType="School_Implementation__c" subject="Update on your teacher implementations" replyTo="trevor.gill@reasoningmind.org"> <messaging:plainTextEmailBody > Dear {!recipient.salutation} {!recipient.lastname}, <c:classlist_controller ContactId="{!recipient.Id}"/> </messaging:plainTextEmailBody> </messaging:emailTemplate>
Visualforce component:
<apex:component controller="TeacherlistatSchoolX2" access="global"> <apex:attribute name="ContactId" description="This is the contact Id." type="Id" assignTo="{!thisContactId}"/> [ Teacher Name ] - [ Grade ] <apex:repeat var="cx" value="{!Classlist}"> [ {!cx.Teacher_Implementation__r.Name} ] - [ {!cx.Grade__c} ] </apex:repeat> </apex:component>
Apex controller:
public class TeacherlistatSchoolX2{ public Id thisContactId {get;set;} public List<Teacher_Implementation__c> theWholeList { get; set; } public List<Class_Implementation__c> Classlist { get; set; } public TeacherlistatSchoolX2(){ theWholeList = new List<Teacher_Implementation__c>(); Classlist = new List<Class_Implementation__c>(); theWholeList = [SELECT Id, Name, School_Implementation__r.Name, School_Implementation__r.Principal_Name__c, School_Implementation__r.Id FROM Teacher_Implementation__c WHERE School_Implementation__r.Principal_Name__c = :thisContactId]; Classlist = [SELECT Id, Name, Teacher_Implementation__r.Name, Grade__c, Teacher_Implementation__r.Id FROM Class_Implementation__c WHERE Teacher_Implementation__r.id IN :theWholeList ORDER BY Teacher_Implementation__r.Name, Grade__c]; } }