You need to sign in to do that
Don't have an account?
Having problems setting up a loop query.
What I would like to accomplish is a apex class that will trigger everytime a report is generated. It will query all Oppourtunities and then assign them a Activity Status based on the last Activity date. This is what I have so far with the current error I am recieving. I know it needs ton of work and any help would be apprecited.
Here is the requirements:
Activity Status wil be High
If Opportunity.LAST_ACTIVITY_DATE is greater than 14 days
Medium
If Opportunity.LAST_ACTIVITY_DATE is in-between 7 and 14
days
Low
If Opportunity.LAST_ACTIVITY_DATE is less than 7 days.
Chris
Error: Compile Error: Initial term of field expression must be a concrete SObject: LIST<Opportunity> at line 7 column 16
Public class OppPoliceController {
List<Opportunity> O = [SELECT LastActivityDate, Activity_Status__c FROM Opportunity]; {
If (O.LastActivityDate > (today() - 14)) {
O.Activity_Status__c = 'High';
}
else if (O.LastActivityDate >= (today() - 7)) {
O.Activity_Status__c = 'Medium';
}
else if (O.Last_Activity_Date < (today() - 14)) {
O.Activity_Status__c = 'Medium';
}
else if (O.LastActivityDate > (today() - 7))
O.Activity_Status__c = 'Low';
update O;
}
}
A few things to say about this:
1) You can do this with workflows and field updates.
2) You cannot create a loop with the following syntax:
You mean to do
3) It's never a good idea to query for all of something without a where clause. You really need ALL opportunities? When you have more than 50,000 Oppty records this code will break.
4) Never put DML inside of loops. Update your list of opportunities after you have changed the Activity_Status__c.
Question, can I include Chatter in the workflows and field updates? I also would like to implement for example:
High
If Opportunity.LAST_ACTIVITY_DATE and Opportunity.Chatter.Last_Post_Date are greater than 14 days
Med
If Opportunity.LAST_ACTIVITY_DATE and Opportunity.Chatter.Last_Post_Date are in between 7 and 14
days
Low
If Opportunity.LAST_ACTIVITY_DATE and Opportunity.Chatter.Last_Post_Date are less than 7 days.
Chris