• arandall
  • NEWBIE
  • 25 Points
  • Member since 2012

  • Chatter
    Feed
  • 1
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 5
    Questions
  • 4
    Replies

Hello,

 

I've got data that I'd like to aggregate and display in a VF email that I'm sending out.  I've been able to display unaggregated data in the email, but when I try to aggregate, I receive errors.

 

From looking at previous posts, I gather that I can't display the data directly from the AggregateResult list that my query generates.  I've attempted to use a wrapper class to remedy this, but when I test my VF email template, I receive the following message: "Error occurred trying to load the template for preview: Attempt to de-reference a null object."

 

Here's my class (I've excluded some code - please let me know if it would be helpful to include it)

public class AlexsClass{


    public Id thisContactId {get;set;}
    public List<Class_Implementation__c> Classlist;
    public List<AggregateResult> Metriclist;
    public List<Summary> Summaries;
    
/*...collecting data that allows me to perform my SOQL query...*/
    
    //A wrapper class that is supposed to capture data from the Aggregate Results list
    public class Summary{
        public String Percent_A {get; set;}
        public String Grade {get; set;}
    
       public Summary(string a, string g){
            this.Percent_A=a;
            this.Grade=g;
       }
    }
    
    //Aggregating the class metrics
    public List<AggregateResult> getMetriclist() {
        if (Metriclist == null) {
            List<AggregateResult> Metriclist =
            [SELECT AVG(A__c) A__c, Start_Date__c,
            COUNT(Class_Implementation__r.Id) Id, COUNT(class_grade__c) Class_Grade
            FROM Class_Metric__c
            WHERE Class_Implementation__r.Id IN :getClasslist()
            GROUP BY Start_Date__c];
        }
        return Metriclist;
    }
    
    //Attempting to wrap the aggregates in the new class
    public List<Summary> summaries = new List<Summary>();

    public List<Summary> getSummaries(){
        for (AggregateResult metrics : Metriclist) { 
            summaries.add(new Summary((String.valueOf(metrics.get('A__c'))), String.valueOf(metrics.get('class_grade'))));
            }
        return summaries;
    }
}

 

Here's my VF component:

<apex:component controller="AlexsClass" access="global">
<apex:attribute name="ContactID" description="This is the contact Id." type="Id" assignTo="{!thisContactId}"/>


[ %A ] - [ % of scheduled time online ] - [ Hours Online ]

<apex:repeat var="sum" value="{!Summaries}">

[ {!sum.Grade} ] [ {!sum.Percent_A} ]

</apex:repeat>

</apex:component>

 

And here's my VF Email template:

<messaging:emailTemplate subject="Here are your metrics!" recipientType="Contact" relatedToType="School_Implementation__c">
<messaging:PlainTextEmailBody >
Dear {!recipient.salutation} {!recipient.lastname},

<c:Alex_s_Controller ContactID="{!recipient.Id}"/>

</messaging:PlainTextEmailBody>   
</messaging:emailTemplate>

 

Any help you can provide would be greatly appreciated!

Hi all,

 

I'm trying to experiment with the new generally available Visualforce charting in one of my sandboxes, and I've found myself stumped.  Here's the situation:

 

I've got an object called Teacher Implementation that has a master-detail relationship with an object called Class Implementation.  The Class Implementation object has a field called "# of students in class".  I would like to display a line graph on the Teacher Implementation record showing the number of students in the related classes, ordered by the created dates of the classes.

 

Here's my controller:

 

public class testTIControllerExtension {

private final Teacher_Implementation__c TI;

public testTIControllerExtension(ApexPages.StandardController stdController) {
this.TI = (Teacher_Implementation__c)stdController.getRecord();
}

 

//Create a method that retrieves the related classes
public List<Class_Implementation__c> getClasses() {
        return [SELECT name, createddate, Teacher_Implementation__c, of_Students_in_Class__c FROM Class_Implementation__c WHERE Teacher_Implementation__c = :ApexPages.currentPage().getParameters().get('id')];
}
}

 

and here is my VF page:

 

<apex:page standardController="Teacher_Implementation__c" extensions="testTIControllerExtension">
<apex:chart data="{!classes}" width="600" height="400">
<apex:axis type="Category" position="left" fields="createddate" title="Created Date"/>
<apex:axis type="Numeric" position="bottom" fields="of_Students_in_Class__c" title="Students"/>
<apex:lineSeries title="Closed-Lost" axis="left" xField="createddate" yField="of_Students_in_Class__c"
markerType="circle" markerSize="4" markerFill="#8E35EF"/>
</apex:chart>
<apex:dataTable value="{!classes}" var="c">
<apex:column headerValue="Created Date" value="{!c.createddate}"/>
<apex:column headerValue="Students" value="{!c.of_Students_in_Class__c}"/>
</apex:dataTable>
</apex:page>

 

Currently, this displays only a table of data, no chart.  This makes me think that my controller's working okay, but that there is something amiss with my VF page.  Then again, I don't feel like I have a great grasp of controller extensions, so something could certainly be wrong there, too.

 

I'd greatly appreciate any insight!

I've got a change set with two workflows, a custom field, a field update, an email alert, and an email template that I'm trying to deploy.

When I try to validate it prior to deployment, it fails due to an error in one of our test classes.  When one of our other admins tries to validate it, it succeeds.

Any idea what might be causing this discrepancy?

Hello,

 

I have a validation rule that requires the BillingState field to be populated for an Account to be created.  I'm trying to deploy a test class that creates test Account records, and when I validate the change set, it fails, indicating that the validation rule was set off.  The odd thing is that I'm populating the BillingState field of the test Account records in the test class, so I can't figure out what the validation rule is still being set off.  Any thoughts as to why this might be happening?

 

The error condition formula for my validation rule is ISBLANK(BillingState), and here's my test class:

 

@isTest
private class testSchoolImpLink {

static testMethod void myTest() {

//Insert Accounts
List<Account> accounts = new List<Account>();
for(Integer i=0; i<5; i++){
Account a = new Account(Name = 'Test Account' + i, BillingState = 'TX');
accounts.add(a);

}
insert accounts;

//Insert an Opportunity
Opportunity o = new Opportunity(Name = 'Test Opportunity', StageName = 'Lead', CloseDate = date.newInstance(2011, 5, 2));
insert o;

//Get accounts back
List<Account> new_accounts = [SELECT id FROM Account];
Opportunity opp = [SELECT id FROM Opportunity][0];

//Insert School Implementations
List<School_Implementation__c> school_imps = new List<School_Implementation__c>();
for(Integer i=0; i<5; i++){
School_Implementation__c s = new School_Implementation__c(Name = 'Test School Implementation', Enrollment_Opportunity__c = opp.id, School_Implementation_Status__c = 'Active', School__c = new_accounts[i].id);
school_imps.add(s);
}
//Start the test
test.startTest();

insert school_imps;

//Stop the test
test.stopTest();

//Query database for new Accounts
List<Account> newest_accounts = [SELECT id, Most_Recent_School_Implementation__c, BillingState FROM Account];

//For each account, make sure that Current School Implementation is correct
for(Account a : newest_accounts){
System.assert(a.Most_Recent_School_Implementation__c != null);
}
}
}

Hello!

 

I have an object called School Implementation that's got a many-to-one relationship to Account.  I have a lookup field on each Account record that should be kept up-to-date with the most recently created School Implementation record related to that Account.  I have written a trigger to handle single updates or inserts, and I'm not sure how to go about bulkifying it so that mass updates/inserts don't exceed my query limits.  Any help would be greatly appreciated!  Here's my trigger:

 

trigger UpdateSchImpLink on School_Implementation__c (after update, after insert) {
 
    //Take the School Implementation being updated
    School_Implementation__c s = trigger.new[0];
    
    //Get the School's Id
    String account_id = s.School__c;
    
    //Get the School itself
    Account a = [SELECT id, Name, Current_School_Implementation__c FROM Account WHERE id = :account_id][0];
    
    //Update the School's most Current School Implementation 
    a.Current_School_Implementation__c = [SELECT id, School__c, CreatedDate FROM School_Implementation__c WHERE School__c = :account_id ORDER BY CreatedDate DESC LIMIT 1][0].id;
    update a;
    
}

Hi all,

 

I'm trying to experiment with the new generally available Visualforce charting in one of my sandboxes, and I've found myself stumped.  Here's the situation:

 

I've got an object called Teacher Implementation that has a master-detail relationship with an object called Class Implementation.  The Class Implementation object has a field called "# of students in class".  I would like to display a line graph on the Teacher Implementation record showing the number of students in the related classes, ordered by the created dates of the classes.

 

Here's my controller:

 

public class testTIControllerExtension {

private final Teacher_Implementation__c TI;

public testTIControllerExtension(ApexPages.StandardController stdController) {
this.TI = (Teacher_Implementation__c)stdController.getRecord();
}

 

//Create a method that retrieves the related classes
public List<Class_Implementation__c> getClasses() {
        return [SELECT name, createddate, Teacher_Implementation__c, of_Students_in_Class__c FROM Class_Implementation__c WHERE Teacher_Implementation__c = :ApexPages.currentPage().getParameters().get('id')];
}
}

 

and here is my VF page:

 

<apex:page standardController="Teacher_Implementation__c" extensions="testTIControllerExtension">
<apex:chart data="{!classes}" width="600" height="400">
<apex:axis type="Category" position="left" fields="createddate" title="Created Date"/>
<apex:axis type="Numeric" position="bottom" fields="of_Students_in_Class__c" title="Students"/>
<apex:lineSeries title="Closed-Lost" axis="left" xField="createddate" yField="of_Students_in_Class__c"
markerType="circle" markerSize="4" markerFill="#8E35EF"/>
</apex:chart>
<apex:dataTable value="{!classes}" var="c">
<apex:column headerValue="Created Date" value="{!c.createddate}"/>
<apex:column headerValue="Students" value="{!c.of_Students_in_Class__c}"/>
</apex:dataTable>
</apex:page>

 

Currently, this displays only a table of data, no chart.  This makes me think that my controller's working okay, but that there is something amiss with my VF page.  Then again, I don't feel like I have a great grasp of controller extensions, so something could certainly be wrong there, too.

 

I'd greatly appreciate any insight!

Hello,

 

I have a validation rule that requires the BillingState field to be populated for an Account to be created.  I'm trying to deploy a test class that creates test Account records, and when I validate the change set, it fails, indicating that the validation rule was set off.  The odd thing is that I'm populating the BillingState field of the test Account records in the test class, so I can't figure out what the validation rule is still being set off.  Any thoughts as to why this might be happening?

 

The error condition formula for my validation rule is ISBLANK(BillingState), and here's my test class:

 

@isTest
private class testSchoolImpLink {

static testMethod void myTest() {

//Insert Accounts
List<Account> accounts = new List<Account>();
for(Integer i=0; i<5; i++){
Account a = new Account(Name = 'Test Account' + i, BillingState = 'TX');
accounts.add(a);

}
insert accounts;

//Insert an Opportunity
Opportunity o = new Opportunity(Name = 'Test Opportunity', StageName = 'Lead', CloseDate = date.newInstance(2011, 5, 2));
insert o;

//Get accounts back
List<Account> new_accounts = [SELECT id FROM Account];
Opportunity opp = [SELECT id FROM Opportunity][0];

//Insert School Implementations
List<School_Implementation__c> school_imps = new List<School_Implementation__c>();
for(Integer i=0; i<5; i++){
School_Implementation__c s = new School_Implementation__c(Name = 'Test School Implementation', Enrollment_Opportunity__c = opp.id, School_Implementation_Status__c = 'Active', School__c = new_accounts[i].id);
school_imps.add(s);
}
//Start the test
test.startTest();

insert school_imps;

//Stop the test
test.stopTest();

//Query database for new Accounts
List<Account> newest_accounts = [SELECT id, Most_Recent_School_Implementation__c, BillingState FROM Account];

//For each account, make sure that Current School Implementation is correct
for(Account a : newest_accounts){
System.assert(a.Most_Recent_School_Implementation__c != null);
}
}
}