You need to sign in to do that
Don't have an account?
Trigger syntax error
Inside the Developer Console, I am receiving the error:
I believe my syntax defining my List<AggregateResult> is correct.
Unexpected Token '<' on Line 2
I believe my syntax defining my List<AggregateResult> is correct.
trigger CaseHandlerCountAlert on SOBJECT (after insert) { List<AggregateResult> AggregateResultList = [SELECT AccountId, Account.Name name, COUNT(Id) co, Milestone1_Project__c.id, Milestone1_Project__c.Implementation_status__c, Milestone1_Project__c.Client_Advisor_Email__c FROM Case WHERE CreatedDate = LAST_N_DAYS:5 GROUP BY AccountId, Account.Name HAVING COUNT(Id) >= 8 WHERE Id IN :Trigger.New]; for(AggregateResult aggr:AggregateResultList){ system.debug(aggr); Messaging.SingleEmailMessage message = new Messaging.SingleEmailMessage(); if(Milestone1_Project__c.Implementation_status__c == 'LIVE - TRANSITION'){ // Set Outgoing Email to Implementation Coordinator //message.toAddresses = new String[] { test@test.com }; } else if (Milestone1_Project__c.Implementation_status__c == 'Live'){ // Private method *** getAddresses() *** retrieves email address from Customer_Success_Managers Public Group //message.toAddresses = new String[] { "test@test.com" }; } message.setSubject = 'Subject Test Message'; message.setPlainTextBody = 'Account name: ' + aggr.get('name') + ' has ' + (Integer)aggr.get('co') + ' cases opened in the last 8 days.'; Messaging.SingleEmailMessage[] messages = new List<Messaging.SingleEmailMessage> {message}; Messaging.SendEmailResult[] results = Messaging.sendEmail(messages); System.debug('Account Name: ' + aggr.get('name')); } private List<String> getAddresses(){ List<User> UserList = [SELECT id, name, email FROM User WHERE id IN (SELECT userorgroupid FROM groupmember WHERE group.name = 'Customer Success Managers')]; Set<String> emailString = new Set<String>(); for(User u: UserList){ emailstring.add(u.email); } return (emailString); } }
On your first line of Trigger SOBJECT needs to be replaced by API Name of the object on which you are writing trigger.
Regards,
Ramakant
WHERE CreatedDate = LAST_N_DAYS:5 GROUP BY AccountId, Account.Name HAVING COUNT(Id) >= 8 WHERE Id IN :Trigger.New];
You are using two WHERE conditions in your SOQL query
I hope you find the above solution helpful. If it does, please mark as Best Answer to help others too.
Thanks and Regards,
Deepali Kulshrestha
www.kdeepali.com