You need to sign in to do that
Don't have an account?
Timothy Smith
Trigger sending email, ToAddresses depend on conditional
I need to send an email to one of two Public Groups depending on the value of the 3 fields in the `If Statement`. Within the the If and Else blocks I have a `String mailGroup` with the value of the Public Class.Now that I need the Else statement to access that private class with a different Public class name, I am having issues inserting `String mailGroup` , into the Private class `getAddresses()`. The Variable `emailAdds` declared at the top holds the email address values from the `getAddresses()` function. Is it my syntax? I am receiving numerous errors:
`Unexpected token 'private'`
`Unexpected token '<'`
`Unexpected token '>'`
`Method does not exist or incorrect signature: void getAddresses(String) from type CaseHandlerCountAlert`
`Unexpected token 'private'`
`Unexpected token '<'`
`Unexpected token '>'`
`Method does not exist or incorrect signature: void getAddresses(String) from type CaseHandlerCountAlert`
trigger CaseHandlerCountAlert on Case (after insert) { String messageToSend; List<String> ListOfMessages = new List<String>(); Set<Id> AcctIds = new Set<Id>(); List<String> clientEmail; String messageBody; String mailGroup; List<String> emailAdds = getAddresses(mailGroup); List<AggregateResult> AggregateResultList = [SELECT AccountId, Account.Name name, COUNT(Id) co FROM Case WHERE CreatedDate = LAST_N_DAYS:1 AND Id IN :Trigger.New GROUP BY AccountId, Account.Name HAVING COUNT(Id) >= 5 ]; Map<Id, String> accountIdEmailmessageMap = new Map<Id, String>(); for(AggregateResult aggr: AggregateResultList){ String messageToSend = 'Account name: ' + aggr.get('name') + ' has ' + (Integer)aggr.get('co') + ' cases opened in the last 8 days.'; Id accId = (Id)aggr.get('AccountId'); accountIdEmailmessageMap.put(accId,messageToSend); AcctIds.add(accId); } List<Case> caseList = [SELECT Id, AccountId, Account.Name,Parent_Project_if_applicable__r.Implementation_status__c, Parent_Project_if_applicable__r.PM_Implementation_Status__c, Parent_Project_if_applicable__r.RCM_Implementation_Status__c, Parent_Project_if_applicable__r.Client_Advisor_Email__c FROM Case WHERE AccountId IN :AcctIds]; for(Case cl:caseList){ if(cl.Parent_Project_if_applicable__r.Implementation_status__c == 'Live - Closed Project'|| cl.Parent_Project_if_applicable__r.PM_Implementation_Status__c == 'Live - Closed Project'|| cl.Parent_Project_If_Applicable__r.RCM_Implementation_Status__c == 'Live - Closed Project'){ mailGroup = 'Customer Success Managers'; String messageBody = accountIdEmailmessageMap.get(cl.AccountId); Messaging.SingleEmailMessage mail = new Messaging.SingleEmailMessage(); mail.setSenderDisplayName('IT Support'); mail.setToAddresses(emailAdds); mail.Subject = 'Multiple cases created alert message'; mail.setPlainTextBody(messageBody); if(messageToSend != null){ Messaging.sendEmail(new Messaging.SingleEmailMessage[] { mail }); } } else{ mailGroup = 'BI Team'; Messaging.SingleEmailMessage mail = new Messaging.SingleEmailMessage(); mail.SetSenderDisplayName('IT Support'); mail.setToAddresses(emailAdds); mail.Subject = 'Multiple cases created alert message'; mail.setPlainTextBody(messageToSend); if(messageToSend != null){ Messaging.sendEmail(new Messaging.SingleEmailMessage[] { mail }); } } } private List<String> getAddresses(mailGroup){ List<User> UserList = [SELECT id, name, email FROM User WHERE id IN (SELECT userorgroupid FROM groupmember WHERE group.name = :mailGroup)]; List<String> emailString = new List<String>(); for(User u: UserList){ emailstring.add(u.email); } return (emailString); //System.debug(emailString); } }
All Answers
Feel free to follow up if any other errors occur
Colton Wehking is correct you just need to add String before mailGroup in getAddresses method like this.
private List<String> getAddresses(String mailGroup){}
Regards,
Soyab
Thank you for your response. When I change the line of code to meet your's I no longer receive the error messages. However, after the code change, I am receiving `null` when it comes to the public group. I have verified the group name and tried other group names with same result. I appreciate any other insight you may offer. Also if I try to `System.debug(emailString)` at the end of the getAddresses function, I get the error `Unreachable Statement`. Thank you again, for your assistance.
System.LimitException: Too many SOQL queries: 101`. I have even tried by changing the criteria where only 1 record comes through the Trigger.new and still receive the same error.