• wedaft
  • NEWBIE
  • 25 Points
  • Member since 2012

  • Chatter
    Feed
  • 1
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 8
    Questions
  • 20
    Replies

Hi everyone,

 

I have a question about my Apex controller below. I'm having major problems getting my AggregatedResults list to work. Ultimately, I want a list that I can reference in a custom visualforce component. I am an admin, not a developer, so I am sure that I've messed up something that is pretty simple. I don't get any errors or anything, it's just that nothing shows up in the visualforce email template where data from this list should be displayed. The last 10-15 lines of code are the ones of interest. Any help is very much appreciated! Thanks!

 

public class TeacherlistatSchoolX2{


    public Id thisContactId {get;set;} 
    private List<Teacher_Implementation__c> Teacherlist;
    private List<Class_Implementation__c> Classlist;
    private List<AggregateResult> Metriclist;
    
    public List<Teacher_Implementation__c> getTeacherlist() {
        if (Teacherlist == null) {
            Teacherlist = 
            [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];
        }
        return Teacherlist;
    }
    
    public List<Class_Implementation__c> getClasslist() {
        if (Classlist == null) {
            Classlist = [SELECT Id, Name, Teacher_Implementation__r.Name, 
            Teacher_Implementation__r.Id, Grade__c
            FROM Class_Implementation__c 
            WHERE Teacher_Implementation__r.id IN :getTeacherlist()];
        }
        return Classlist;
    }
  
    public List<AggregateResult> getMetriclist() {
    if (Metriclist == null) {
    AggregateResult[] Metriclist =
        [SELECT AVG(A__c), AVG(of_scheduled_time_online__c), AVG(Hours_Online__c), Start_Date__c,
        MIN(Class_Implementation__r.Name), MIN(Class_Implementation__r.Id), MIN(Class_Implementation__r.Date_of_previous_admin_email__c), MIN(class_grade__c)
        FROM Class_Metric__c
        WHERE Class_Implementation__r.Id IN :getClasslist()
        GROUP BY Start_Date__c];
    }
        return Metriclist;
    }
}

 

  • September 25, 2012
  • Like
  • 0

 

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];
    
    }
}

 

  • September 11, 2012
  • Like
  • 0

So here's the background:

 

I have a master-detail hierarchy that goes: School Implementations-->Teacher Implementations-->Class Implementations. There is a lot of data that we store at the Class Implementation level (How many hours has the class used our program, what is the average class score on our program, etc) that we want to email out to a contact, specifically the school principal. I would like to create a visualforce email template that can capture all of the data from the class implementation records that are grandchildren of a school implementation and list them as rows in a single table, something like this:

 

Class Name

Hours online

Problem accuracy

Class A

3.2

78%

Class B

3.8

74%

Class C

2.5

70%

 

My main question, then, is if I have a school (Parent object) with 5 teachers(child object) and each teacher has 3 classes (grandchild object), how do I get all 15 of those classes displayed as rows on a single table in an email template?

 

Is this possible? If so, I would be very grateful for any direction that I can get. Thanks!

  • August 30, 2012
  • Like
  • 0

Hi all,

 

I'm creating a trigger that should update a field on a custom object called "COTM Protocols" whenever an email with a certain subject is sent to the contact related to that protocol. I had the trigger working fine, but I had a SOQL query inside a FOR loop so I have to bulkify it. I'm giving it my best shot, but can't seem to make it work. No error messages, but the field isn't updating the way it's supposed to. Here's my code:

 

trigger UpdateCOemaildateOnProtocol on Task (after insert) {

 List<task> tasks = trigger.new;
    
    //Get list of Teacher IDs
    List<Id> teacher_ids = new List<Id>();
    for (task t : tasks){
        teacher_ids.add(t.WhoId);
    }


//Produce data for protocols
List<COTM_Protocol__c> protocols = 
[SELECT  id, CO_Follow_up_sent_trigger__c, CO_number__c, subject__c, Teacher_Implementation__r.Name 
FROM  COTM_Protocol__c 
WHERE Teacher_Implementation__r.Name LIKE '%2012-2013'
];


for (task t : tasks){
    for (COTM_protocol__c p: protocols){
  
        if (t.CO_number__c == p.CO_number__c)
        if (t.WhoId == p.subject__c)
        if (p.Teacher_Implementation__r.Name.contains('2012-2013'))
        if (p.CO_Follow_up_sent_trigger__c == null){
        
    
p.CO_Follow_up_sent_trigger__c = t.ActivityDate;
p.CO_email_sent__c = true;

}

}
}
//update the protocol
update protocols;


}

 

Thank you!

  • August 10, 2012
  • Like
  • 0

I need to create a trigger that does the following:

 

Whenever a new task with a subject of "Email: CO1 Feedback" is created on a contact record, a field on that contact record called "CO1_followup_email_date__c" should be updated to match the date that the task was created.

 

The code that I used is below. I am not getting any error messages, but when I create the task with the proper subject line, the CO1 Follow-up email date is not updated. Any ideas?? Thanks for your help!

 

trigger Contactbirthdayupdate on Task (after insert) 
{
List<Contact> ContactsToUpdate = new List<Contact>();
for (Task t: Trigger.new)
{
if (t.subject=='Email: CO1 Feedback')
{
Contact c = new Contact(Id=t.WhatId);

c.CO1_Followup_email_date__c = t.ActivityDate;
ContactsToUpdate.add(c);
}
}
   try {
        update ContactsToUpdate; 
    } catch (system.Dmlexception e) {
        system.debug (e);
    }
}

 

  • August 07, 2012
  • Like
  • 0

I've created a trigger to create new child records (COTM_Protocol__c) when certain conditions are met on the teacher implementation record (Teacher_Implementation__c). I am not getting any errors when I save the trigger, and I'm not getting any errors when I save the parent record with the conditions that should set off the trigger. No error messages, it's just that no new records are being created. Any idea of where I am going wrong, based on the code below?

 

trigger createCOTMOnTeacherImplementationX on Teacher_Implementation__c (after insert, after update) {
    
    List <COTM_Protocol__c> COTMToInsert = new List <COTM_Protocol__c> (); 
    
    for (Teacher_Implementation__c TI : Trigger.new) {
        
        if(TI.trigger_lock__c == true)
        if(TI.of_Observations_Required__c == 1) {
        
        //NEW COTM//
        COTM_Protocol__c COTM1 = new COTM_Protocol__c (); 

        COTM1.Teacher_Implementation__c = TI.ID; 
        COTM1.CO_due_date__c = TI.CO1_due__c;
        COTM1.Observer_User__c = TI.School_Implementation__r.OwnerId;
       
        COTMToInsert.add(COTM1);
        
        } else 
        if(TI.trigger_lock__c == true)
        if(TI.of_Observations_Required__c == 2) {
       
        //NEW COTM//
        COTM_Protocol__c COTM2 = new COTM_Protocol__c (); 

        COTM2.Teacher_Implementation__c = TI.ID; 
        COTM2.CO_due_date__c = TI.CO1_due__c;
        COTM2.Observer_User__c = TI.School_Implementation__r.OwnerId;
        
        //NEW COTM//
        COTM_Protocol__c COTM3 = new COTM_Protocol__c (); 

        COTM3.Teacher_Implementation__c = TI.ID; 
        COTM3.CO_due_date__c = TI.CO2_due__c;
        COTM3.Observer_User__c = TI.School_Implementation__r.OwnerId;

        
        COTMToInsert.add(COTM2);
        COTMToInsert.add(COTM3);
        
       
        
        }//end if
        
    }//end for
    
    
         try {
        insert COTMToInsert; 
    } catch (system.Dmlexception e) {
        system.debug (e);
    }

    
}

 

Thanks!

 

  • August 02, 2012
  • Like
  • 0

I have a custom object called Observation Summary (Observation_Summary__c), and within that object I have a field called Date of Assessment (Date_of_Assessment__c). I would like to create a trigger that does the following:

 

Whenever an email is sent from the Observation Summary record, and that email's subject begins with "Observation feedback", the Date of Assessment field on the Observation Summary should update to become the date that the email was sent.

 

Is this possible? Thanks for your help!

Hi everyone,

 

I am trying to create a Apex trigger that automatically creates a new task record for me once a checkbox field named "School Assigned" on my custom object, "Buffalo", is checked. I want a lot of the fields in the new task record to be automatically populated in the process. The code creates the new tasks fine, but unfortunately I have been having a lot of trouble setting up the code to populate the following default fields on the Task object: 1. Owner (AKA Assigned to) and 2. What (AKA Related to). The code is copied below, with the problem lines of code in blue and the corresponding error message I get in red. I know very little about Apex, any help is very much appreciated!

 

--------------------------------------------------------------------------------------------------------------------------------------------------------

 

trigger createTaskOnBuffaloX on Buffalo__c (after insert, after update) {

List <task> taskToInsert = new List <task> ();

for (Buffalo__c b : Trigger.new) {

if (b.School_assigned__c == true) {

task task = new task ();

task.ActivityDate = b.First_CO__c;
task.Subject = 'First CO';
task.owner = b.owner;   Error: Compile Error: Field is not writeable: Owner

task.what = b.name; Error: Compile Error: Illegal assignment from String to SOBJECT:Name



taskToInsert.add(task);


}//end if

}//end for o

try {
insert taskToInsert;
} catch (system.Dmlexception e) {
system.debug (e);
}

}

Hi everyone,

 

I have a question about my Apex controller below. I'm having major problems getting my AggregatedResults list to work. Ultimately, I want a list that I can reference in a custom visualforce component. I am an admin, not a developer, so I am sure that I've messed up something that is pretty simple. I don't get any errors or anything, it's just that nothing shows up in the visualforce email template where data from this list should be displayed. The last 10-15 lines of code are the ones of interest. Any help is very much appreciated! Thanks!

 

public class TeacherlistatSchoolX2{


    public Id thisContactId {get;set;} 
    private List<Teacher_Implementation__c> Teacherlist;
    private List<Class_Implementation__c> Classlist;
    private List<AggregateResult> Metriclist;
    
    public List<Teacher_Implementation__c> getTeacherlist() {
        if (Teacherlist == null) {
            Teacherlist = 
            [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];
        }
        return Teacherlist;
    }
    
    public List<Class_Implementation__c> getClasslist() {
        if (Classlist == null) {
            Classlist = [SELECT Id, Name, Teacher_Implementation__r.Name, 
            Teacher_Implementation__r.Id, Grade__c
            FROM Class_Implementation__c 
            WHERE Teacher_Implementation__r.id IN :getTeacherlist()];
        }
        return Classlist;
    }
  
    public List<AggregateResult> getMetriclist() {
    if (Metriclist == null) {
    AggregateResult[] Metriclist =
        [SELECT AVG(A__c), AVG(of_scheduled_time_online__c), AVG(Hours_Online__c), Start_Date__c,
        MIN(Class_Implementation__r.Name), MIN(Class_Implementation__r.Id), MIN(Class_Implementation__r.Date_of_previous_admin_email__c), MIN(class_grade__c)
        FROM Class_Metric__c
        WHERE Class_Implementation__r.Id IN :getClasslist()
        GROUP BY Start_Date__c];
    }
        return Metriclist;
    }
}

 

  • September 25, 2012
  • Like
  • 0

So here's the background:

 

I have a master-detail hierarchy that goes: School Implementations-->Teacher Implementations-->Class Implementations. There is a lot of data that we store at the Class Implementation level (How many hours has the class used our program, what is the average class score on our program, etc) that we want to email out to a contact, specifically the school principal. I would like to create a visualforce email template that can capture all of the data from the class implementation records that are grandchildren of a school implementation and list them as rows in a single table, something like this:

 

Class Name

Hours online

Problem accuracy

Class A

3.2

78%

Class B

3.8

74%

Class C

2.5

70%

 

My main question, then, is if I have a school (Parent object) with 5 teachers(child object) and each teacher has 3 classes (grandchild object), how do I get all 15 of those classes displayed as rows on a single table in an email template?

 

Is this possible? If so, I would be very grateful for any direction that I can get. Thanks!

  • August 30, 2012
  • Like
  • 0

I need to create a trigger that does the following:

 

Whenever a new task with a subject of "Email: CO1 Feedback" is created on a contact record, a field on that contact record called "CO1_followup_email_date__c" should be updated to match the date that the task was created.

 

The code that I used is below. I am not getting any error messages, but when I create the task with the proper subject line, the CO1 Follow-up email date is not updated. Any ideas?? Thanks for your help!

 

trigger Contactbirthdayupdate on Task (after insert) 
{
List<Contact> ContactsToUpdate = new List<Contact>();
for (Task t: Trigger.new)
{
if (t.subject=='Email: CO1 Feedback')
{
Contact c = new Contact(Id=t.WhatId);

c.CO1_Followup_email_date__c = t.ActivityDate;
ContactsToUpdate.add(c);
}
}
   try {
        update ContactsToUpdate; 
    } catch (system.Dmlexception e) {
        system.debug (e);
    }
}

 

  • August 07, 2012
  • Like
  • 0

I've created a trigger to create new child records (COTM_Protocol__c) when certain conditions are met on the teacher implementation record (Teacher_Implementation__c). I am not getting any errors when I save the trigger, and I'm not getting any errors when I save the parent record with the conditions that should set off the trigger. No error messages, it's just that no new records are being created. Any idea of where I am going wrong, based on the code below?

 

trigger createCOTMOnTeacherImplementationX on Teacher_Implementation__c (after insert, after update) {
    
    List <COTM_Protocol__c> COTMToInsert = new List <COTM_Protocol__c> (); 
    
    for (Teacher_Implementation__c TI : Trigger.new) {
        
        if(TI.trigger_lock__c == true)
        if(TI.of_Observations_Required__c == 1) {
        
        //NEW COTM//
        COTM_Protocol__c COTM1 = new COTM_Protocol__c (); 

        COTM1.Teacher_Implementation__c = TI.ID; 
        COTM1.CO_due_date__c = TI.CO1_due__c;
        COTM1.Observer_User__c = TI.School_Implementation__r.OwnerId;
       
        COTMToInsert.add(COTM1);
        
        } else 
        if(TI.trigger_lock__c == true)
        if(TI.of_Observations_Required__c == 2) {
       
        //NEW COTM//
        COTM_Protocol__c COTM2 = new COTM_Protocol__c (); 

        COTM2.Teacher_Implementation__c = TI.ID; 
        COTM2.CO_due_date__c = TI.CO1_due__c;
        COTM2.Observer_User__c = TI.School_Implementation__r.OwnerId;
        
        //NEW COTM//
        COTM_Protocol__c COTM3 = new COTM_Protocol__c (); 

        COTM3.Teacher_Implementation__c = TI.ID; 
        COTM3.CO_due_date__c = TI.CO2_due__c;
        COTM3.Observer_User__c = TI.School_Implementation__r.OwnerId;

        
        COTMToInsert.add(COTM2);
        COTMToInsert.add(COTM3);
        
       
        
        }//end if
        
    }//end for
    
    
         try {
        insert COTMToInsert; 
    } catch (system.Dmlexception e) {
        system.debug (e);
    }

    
}

 

Thanks!

 

  • August 02, 2012
  • Like
  • 0

I have a custom object called Observation Summary (Observation_Summary__c), and within that object I have a field called Date of Assessment (Date_of_Assessment__c). I would like to create a trigger that does the following:

 

Whenever an email is sent from the Observation Summary record, and that email's subject begins with "Observation feedback", the Date of Assessment field on the Observation Summary should update to become the date that the email was sent.

 

Is this possible? Thanks for your help!

Hi everyone,

 

I am trying to create a Apex trigger that automatically creates a new task record for me once a checkbox field named "School Assigned" on my custom object, "Buffalo", is checked. I want a lot of the fields in the new task record to be automatically populated in the process. The code creates the new tasks fine, but unfortunately I have been having a lot of trouble setting up the code to populate the following default fields on the Task object: 1. Owner (AKA Assigned to) and 2. What (AKA Related to). The code is copied below, with the problem lines of code in blue and the corresponding error message I get in red. I know very little about Apex, any help is very much appreciated!

 

--------------------------------------------------------------------------------------------------------------------------------------------------------

 

trigger createTaskOnBuffaloX on Buffalo__c (after insert, after update) {

List <task> taskToInsert = new List <task> ();

for (Buffalo__c b : Trigger.new) {

if (b.School_assigned__c == true) {

task task = new task ();

task.ActivityDate = b.First_CO__c;
task.Subject = 'First CO';
task.owner = b.owner;   Error: Compile Error: Field is not writeable: Owner

task.what = b.name; Error: Compile Error: Illegal assignment from String to SOBJECT:Name



taskToInsert.add(task);


}//end if

}//end for o

try {
insert taskToInsert;
} catch (system.Dmlexception e) {
system.debug (e);
}

}