You need to sign in to do that
Don't have an account?
Class: Set variables
Hello,
I'm a novice programmer at best - trying to teach myself. I know how to set/declare variables in triggers, but I'm not sure how to go about it in a class. I'm working on building VF emails and I would like the class to pull a field value from the record that is is generated from.
We have a object for Territories (Territory__c), we would like to send out activity reports to our group each night with all of the Tasks and Events completed for that territory. The salesforce scheduled reports aren't scalable since we need one per territory and can only send one per hour. I would like to pull the Territory Name field in as a veriable, then query tasks/events that match that - Activities have a field called Territory__c that will match the name. Here is my class:
public class TerritoryActivity{ private final List<Task> t; private final List<Event> e; public TerritoryActivity(){ t = [SELECT id, Territory__c, Assigned_Name__c, Firm_Name__c, Contact_Name__c, State__c,Description, Subject, Outcome__c, Type FROM Task WHERE Date_Completed__c = Yesterday AND Outcome__c = 'Success' AND Territory__c = 'New England']; e = [SELECT id, Territory__c, Assigned_Name__c, Firm_Name__c, Contact_Name__c, State__c,Description, Subject, Outcome__c, Type FROM Event WHERE Date_Completed__c = Yesterday AND Outcome__c = 'Meeting Occurred' AND Territory__c = 'New England']; } public List<Task> getCalls(){ return t; } public List<Event> getMeetings(){ return e; } }
Blake:
You'll get QueryExceptions on your Select SOQL if the where clause is not satisfied
use this -- the caller will deal with empty lists naturally and not have to test for null
Hi Eric,
Thanks for your responce, I put this code inplace in the class, but in the VF template I'm getting an error: "Unknown constructor 'TerritoryActivity.TerritoryActivity()'." Do I need to change part of the component since you added TerrtitoryActivity(String terr)?
Blake -- sorry - I didn't realize this was going to be referenced by a VF component
0 - Remove territory from the constructor
1 - I would move the select statements out of the constructor and have them invoked within the getCalls(), getMeetings() methods
2 - That said, I don't see how your component knows what is the specific territory to use for the query. Is this user input? Normally, this would be done as a component parameter:
Read up on this in the VF doc on components using custom controllers. You'll need to create a getter/setter territory in your controller