function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
Dchris222Dchris222 

Trying to Query Oppertunity and Chatter Information

I am attemping to querry all Oppertunities and Chatter feed posts on all the oppertunites. I then would to evalute the Oppertunities based on LastActivityDate and Chatter feed posts by CreatedDate and update a picklist named Activity Status with High, Medium, or Low. This would be ran nightly and would be eventually fed into a report.

 

This is what I have so far. I don't think I did the query correctly because it is giving me the error: "Error: Compile Error: Didn't understand relationship 'FeedComments' in FROM part of query call. If you are attempting to use a custom relationship, be sure to append the '__r' after the custom relationship name. Please reference your WSDL or the describe call for the appropriate names. at line 3 column 32"

 

To sum it up: Am I querrying this correctly and also am I assigning the value (High, Medium, Low) correctly to the Activity_Status Picklist?

 

public class OppPoliceController {

    List<Opportunity> Opptys = [SELECT LastActivityDate, Activity_Status__c, (SELECT CreatedDate FROM FeedComments ORDER BY CreatedDate DESC) FROM Opportunity]];
    
    //Loop through Opportunities only once
    for(Opportunity o : Opptys){
        
         //Loop through related FeedComments only once
         for(FeedComments f : o.Opportunity){
         
            if(f.CreatedDate > (today() - 14) Or o.LastActivityDate > (today() - 14)){
                
                Opp = Database.query(Opptys);
                Activity_Status__c = 'High';
                update Opptys;
                return null;
            }
            else if(f.CreatedDate >= (today() - 7) Or o.LastActivityDate >= (today() - 7)){
            
                Opp = Database.query(Opptys);
                Activity_Status__c = 'Medium';
                update Opptys;
                return null;
            }
            else if(f.CreatedDate < (today() - 14) Or o.LastActivityDate < (today() - 14)){
                
                Opp = Database.query(Opptys);
                Activity_Status__c = 'Medium';
                update Opptys;
                return null;
            }
            else if(f.CreatedDate > (today() - 7) Or o.LastActivityDate > (today() - 7)){
                
                Opp = Database.query(Opptys);
                Activity_Status__c = 'Low';
                update Opptys;
                return null;
            }
         }
    
   }
}

Dchris222Dchris222

Havn't recieved any replies on this, any help would still be appreciated.