• Timothy Smith
  • NEWBIE
  • 105 Points
  • Member since 2017

  • Chatter
    Feed
  • 0
    Best Answers
  • 1
    Likes Received
  • 0
    Likes Given
  • 32
    Questions
  • 12
    Replies
My Trigger sends an email message when an Account has 8 cases created within 7 days. The Case object has a Lookup relationship to the Milestone1__project__c object has a relationship name Parent_Project_If_Applicable__r.

If any of these fields are equal to 'Live - Closed Project':
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

Then the Email is sent to the address in the IF BLock. Any other value the email is sent through the Else Block.
Every test pass except setup. I am trying to create a user (preferably two) with email addresses. I found that the fields Parent_Project_if_applicable__r.Resource_Coordinator_Email__c and Parent_Project_if_applicable__r.Client_Advisor_Email__c are formula fields grabbing the email in a formula that looks like this Client_Advisor__r.Email and Resource_Coordinator_Email__c .
How do I add Insert the user so that I can test that the emails would go to the right destination?
 
System.DmlException: Insert failed. First exception on row 0; first error: CANNOT_INSERT_UPDATE_ACTIVATE_ENTITY, CaseHandlerCountAlert: execution of AfterInsert

caused by: System.EmailException: SendEmail failed. First exception on row 0; first error: INVALID_EMAIL_ADDRESS, Email address is invalid: null: [toAddresses, null]

Trigger.CaseHandlerCountAlert: line 78, column 1: []

Test Class:
 
@isTest
private class TestCaseHandlerAlert {

    @TestSetup static void setup(){
       //Create user to populate field Resource Coord. and Implementation Spec.

        Profile p = [SELECT Id FROM Profile WHERE Name='Standard User']; 
        User u = new User(Alias = 'testER', Email='standarduser@testorg.com', 
            EmailEncodingKey='UTF-8', LastName='Testing', LanguageLocaleKey='en_US', 
            LocaleSidKey='en_US', ProfileId = p.Id, 
            TimeZoneSidKey='America/Los_Angeles', UserName='standarduser101@testorg.com');

        insert u;
        system.debug(u.email);

       // Create and Insert 2 Accounts

        Account a = new Account();
        Account b = new Account();
            a.name = 'testacct21';
            b.name = 'testacct31';



 //Set Contact id to variables
 //  Id userIDToInsert = [select id from User Where username='standarduser101@testorg.com'].id;


  // Create Milestones

 //This Milestone will fire the If Block    
  Milestone1_Project__c project1 = new Milestone1_Project__c();
        project1.Name = 'triggertestLIVE';
        project1.RCM_Implementation_Status__c = 'LIVE - CLOSED PROJECT';
        project1.PM_Implementation_Status__c= 'RETURNED SOFTWARE';
        project1.Implementation_Status__c= 'RETURNED SOFTWARE';
        project1.Resource_Coordinator__c = u.Id;
        project1.Client_Advisor__c = u.Id;


 Milestone1_Project__c project = new Milestone1_Project__c();
        project.Name = 'triggertest21';
        project.RCM_Implementation_Status__c = 'RETURNED SOFTWARE';
        project.PM_Implementation_Status__c= 'RETURNED SOFTWARE';
        project.Implementation_Status__c= 'RETURNED SOFTWARE';
        project1.Resource_Coordinator__c = u.Id;
        project1.Client_Advisor__c = u.id;


     //Insert Account
    insert a;
    insert b;
    //Insert Project
    insert project;
    insert project1;

    //Create 10 Cases associated with Project

    List<Case> casesToInsert = new List<Case>();
    List<Case> casesToInsert1 = new List<Case>();

        for (Integer i=1; i<10; i++){

            Case c = new Case();
                c.AccountId = a.id;
                c.Origin = 'Phone';
                c.Impact__c = 'Low';
                c.Severity__c = 'Minor';
                c.Type = 'Bridge';
                c.Parent_Project_if_applicable__c = project1.id;

            casesToInsert.add(c);
         }

        for (Integer i=1; i<10; i++){  
        Case c1 = new Case();
        c1.AccountId = b.id;
        c1.Origin = 'Phone';
        c1.Impact__c = 'Low';
        c1.Severity__c = 'Minor';
        c1.Type = 'Bridge';
        c1.Parent_Project_if_applicable__c = project.id;

        casesToInsert.add(c1);
    }          



      insert casesToInsert; 
      insert casesToInsert1;

    }



@isTest static void DontSendNotLimit (){
        // Do not send, not enough Cases need 8 
        List<Case> testCases = [SELECT Id FROM Case WHERE Account.Name='testacct21' LIMIT 5];
        List<Case> insertCases = new List<Case>();   

      Test.startTest();
        insert insertCases;
        System.debug('Should be 0 emails sent: ' + Limits.getEmailInvocations());
      Test.stopTest();
    }

@isTest static void SendElseBlock (){
        // Else BLock Fires - 2 emails sent 
        List<Case> testCases = [SELECT Id FROM Case WHERE Account.Name='testacct21' LIMIT 8];
        List<Case> insertCases = new List<Case>();   

      Test.startTest();
        insert insertCases;
        System.debug('Should be 3: ' + Limits.getEmailInvocations());
      Test.stopTest();
    }   



@isTest static void SendRCMiFBlock (){
        // Fires the If BLock 1/3
        List<Case> testCases = [SELECT Id FROM Case WHERE Account.Name='testacct31' LIMIT 8];
        List<Case> insertCases = new List<Case>();  
        for(Case cas :testCases ){

                insertCases.add(cas);
            } 

      Test.startTest();
        insert insertCases; 
      Test.stopTest();
    }

    @isTest static void SendPMiFBlock (){
        // Fires the If BLock 2/3
        List<Case> testCases = [SELECT Id FROM Case WHERE Account.Name='testacct31' LIMIT 8];
        List<Case> insertCases = new List<Case>();  
        for(Case cas :testCases ){

                cas.Parent_Project_if_applicable__r.PM_Implementation_Status__c = 'LIVE - CLOSED PROJECT';
                insertCases.add(cas);
            } 

      Test.startTest();
        insert insertCases; 
      Test.stopTest();
    }

    @isTest static void SendIMPiFBlock (){
        // Fires the If BLock 3/3
        List<Case> testCases = [SELECT Id FROM Case WHERE Account.Name='testacct31' LIMIT 8];
        List<Case> insertCases = new List<Case>();  
        for(Case cas :testCases ){
                cas.Parent_Project_if_applicable__r.Implementation_Status__c= 'LIVE - CLOSED PROJECT';
                insertCases.add(cas);
            } 

      Test.startTest();
        insert insertCases; 
      Test.stopTest();
    }


}

Trigger:
 
trigger CaseHandlerCountAlert on Case (after insert, after update) {

//Case trigger that will send email alert when 8 cases are created within 7 days.
String messageToSend;
List <String> ListOfMessages = new List <String>();
Set <Id> AcctIds = new Set <Id>();
String messageBody;

List < AggregateResult > AggregateResultList = [SELECT AccountId, Account.Name name, COUNT(Id) co
                                                FROM Case
                                                WHERE CreatedDate = LAST_N_DAYS:7 AND Id IN :Trigger.New
                                                GROUP BY AccountId, Account.Name
                                                HAVING COUNT(Id) >= 8
                                               ];

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.Resource_Coordinator_Email__c,
                          Parent_Project_if_applicable__r.Client_Advisor_Email__c                      
                          FROM Case
                          WHERE AccountId IN: AcctIds];

List<Messaging.SingleEmailMessage> lstASingleEmailMessage = new List<Messaging.SingleEmailMessage>();
List<Messaging.SingleEmailMessage> lstBSingleEmailMessage = new List<Messaging.SingleEmailMessage>();

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') {

            String messageBody = accountIdEmailmessageMap.get(cl.AccountId);

            List<String> emailaddr = new List<String>();
            emailaddr.add('GlobalEmailAddress@domain.com');  

            Messaging.SingleEmailMessage mail = new Messaging.SingleEmailMessage();
            mail.setSenderDisplayName('Support');
            mail.setToAddresses(emailaddr);   
            mail.Subject = 'Multiple cases created alert message';
            mail.setPlainTextBody(messageBody);
            lstASingleEmailMessage.add(mail);




        }else{
            String messageBody1 = accountIdEmailmessageMap.get(cl.AccountId);        

            List<String> emailAdds = new List<String>();
            emailAdds.add(cl.Parent_Project_if_applicable__r.Resource_Coordinator_Email__c);
            emailAdds.add(cl.Parent_Project_if_applicable__r.Client_Advisor_Email__c); 

            Messaging.SingleEmailMessage amail = new Messaging.SingleEmailMessage();
            amail.SetSenderDisplayName('Support');
            amail.setToAddresses(emailAdds);
            amail.Subject = 'Multiple cases created alert message';
            amail.setPlainTextBody(messageBody1);
            lstBSingleEmailMessage.add(amail);


        }  
}
Messaging.SendEmailResult[] r = Messaging.sendEmail(lstASingleEmailMessage);   
Messaging.SendEmailResult[] rb = 

Messaging.sendEmail(lstBSingleEmailMessage);
}


​​​​​​​

I get 100% test coverage but receiving error on setup method:
`System.NullPointerException: Attempt to de-reference a null object
(TestCasehandlerAlert.setup: line 17, column 1)`

The email address fields are formula fields. The formula fields are `Client_Advisor__r.Email` and `Resource_Coordinator__r.Email.` The trigger will send an email message if an account has 8 cases or more created within 7 days. If the value of any of three specified fields is "Live - Closed Project", the email is sent to a single email address. If any of the three fields is equal to "Live - Closed Project", the Else block is fired and email is sent to two other email addresses.
I am trying to create two types of projects; one will run through the IF statement, the other will run through the Else statement.
Trigger:
 
trigger CaseHandlerCountAlert on Case (after insert) {

//Case trigger that will send email alert when 8 cases are created within 7 days.
String messageToSend;
List <String> ListOfMessages = new List <String>();
Set <Id> AcctIds = new Set <Id>();
String messageBody;

List < AggregateResult > AggregateResultList = [SELECT AccountId, Account.Name name, COUNT(Id) co
                                                FROM Case
                                                WHERE CreatedDate = LAST_N_DAYS:7 AND Id IN :Trigger.New
                                                GROUP BY AccountId, Account.Name
                                                HAVING COUNT(Id) >= 8
                                               ];

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.Resource_Coordinator_Email__c,
                          Parent_Project_if_applicable__r.Client_Advisor_Email__c                      
                          FROM Case
                          WHERE AccountId IN: AcctIds];

List<Messaging.SingleEmailMessage> lstASingleEmailMessage = new List<Messaging.SingleEmailMessage>();
List<Messaging.SingleEmailMessage> lstBSingleEmailMessage = new List<Messaging.SingleEmailMessage>();

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') {

            String messageBody = accountIdEmailmessageMap.get(cl.AccountId);

            List<String> emailaddr = new List<String>();
            emailaddr.add('CustomerSuccessManagers@test.com');  

            Messaging.SingleEmailMessage mail = new Messaging.SingleEmailMessage();
            mail.setSenderDisplayName('Support');
            mail.setToAddresses(emailaddr);   
            mail.Subject = 'Multiple cases created alert message';
            mail.setPlainTextBody(messageBody);
            lstASingleEmailMessage.add(mail);




        }else{
            String messageBody = accountIdEmailmessageMap.get(cl.AccountId);        

            List<String> emailAdds = new List<String>();
            emailAdds.add(cl.Parent_Project_if_applicable__r.Resource_Coordinator_Email__c);
            emailAdds.add(cl.Parent_Project_if_applicable__r.Client_Advisor_Email__c); 

            Messaging.SingleEmailMessage amail = new Messaging.SingleEmailMessage();
            amail.SetSenderDisplayName('Support');
            amail.setToAddresses(emailAdds);
            amail.Subject = 'Multiple cases created alert message';
            amail.setPlainTextBody(messageBody);
            lstBSingleEmailMessage.add(amail);
            System.debug('messageBody: ' + messageBody);
            System.debug('email message: ' + amail);

        }  
}
Messaging.SendEmailResult[] r = Messaging.sendEmail(lstASingleEmailMessage);
Messaging.SendEmailResult[] rb = 

Messaging.sendEmail(lstBSingleEmailMessage);
}


Test Class:
@isTest
private class TestCaseHandlerAlert {

    @isTest static void setup(){
        Account a = new Account();
        Account b = new Account();
            a.name = 'testacct21';
            b.name = 'testacct31';

  // Create Milestone

 Milestone1_Project__c project = new Milestone1_Project__c();
        project.Name = 'triggertest21';
        project.RCM_Implementation_Status__c = 'RETURNED SOFTWARE';
        project.PM_Implementation_Status__c= 'RETURNED SOFTWARE';
        project.Implementation_Status__c= 'RETURNED SOFTWARE';


  Milestone1_Project__c project1 = new Milestone1_Project__c();
        //project.RecordTypeId = '01214000001RYp2AAG';
        project1.Name = 'triggertest31';
        project1.RCM_Implementation_Status__c = 'LIVE - CLOSED PROJECT';
        project1.PM_Implementation_Status__c= 'RETURNED SOFTWARE';
        project1.Implementation_Status__c= 'RETURNED SOFTWARE';


     //Insert Account
    insert a;
    insert b;
    //Insert Project
    insert project;
    insert project1;

    //Create 10 Cases associated with Project

    List<Case> casesToInsert = new List<Case>();
    List<Case> casesToInsert1 = new List<Case>();

        for (Integer i=1; i<12; i++){  
        Case c1 = new Case();
        c1.AccountId = b.id;
        c1.Origin = 'Phone';
        c1.Impact__c = 'Low';
        c1.Severity__c = 'Minor';
        c1.Type = 'Bridge';
        c1.Parent_Project_if_applicable__c = project.id;

        casesToInsert1.add(c1);
    }          

    for (Integer i=1; i<12; i++){

    Case c = new Case();
        c.AccountId = a.id;
        c.Origin = 'Phone';
        c.Impact__c = 'Low';
        c.Severity__c = 'Minor';
        c.Type = 'Bridge';
        c.Parent_Project_if_applicable__c = project1.id;

        casesToInsert.add(c);
    }

      insert casesToInsert; 
      insert casesToInsert1;

    }





@isTest static void DontSendNotLimit (){
        // Do not send, not enough Cases need 8 
        List<Case> testCases = [SELECT Id FROM Case WHERE Account.Name='testacct21' LIMIT 5];
        List<Case> insertCases = new List<Case>();   

      Test.startTest();
        insert insertCases;
        System.debug(Limits.getEmailInvocations());
      Test.stopTest();
    }

@isTest static void SendElseBlock (){
        // Else BLock Fires - 2 emails sent 
        List<Case> testCases = [SELECT Id FROM Case WHERE Account.Name='testacct21' LIMIT 8];
        List<Case> insertCases = new List<Case>();   

      Test.startTest();
        insert insertCases;
        System.debug(Limits.getEmailInvocations());
      Test.stopTest();
    }   



@isTest static void SendRCMiFBlock (){
        // Fires the If BLock 1/3
        List<Case> testCases = [SELECT Id FROM Case WHERE Account.Name='testacct31' LIMIT 8];
        List<Case> insertCases = new List<Case>();  
        for(Case cas :testCases ){

                insertCases.add(cas);
            } 

      Test.startTest();
        insert insertCases; 
      Test.stopTest();
    }

    @isTest static void SendPMiFBlock (){
        // Fires the If BLock 2/3
        List<Case> testCases = [SELECT Id FROM Case WHERE Account.Name='testacct31' LIMIT 8];
        List<Case> insertCases = new List<Case>();  
        for(Case cas :testCases ){

                cas.Parent_Project_if_applicable__r.PM_Implementation_Status__c = 'LIVE - CLOSED PROJECT';
                insertCases.add(cas);
            } 

      Test.startTest();
        insert insertCases; 
      Test.stopTest();
    }

    @isTest static void SendIMPiFBlock (){
        // Fires the If BLock 3/3
        List<Case> testCases = [SELECT Id FROM Case WHERE Account.Name='testacct31' LIMIT 8];
        List<Case> insertCases = new List<Case>();  
        for(Case cas :testCases ){
                cas.Parent_Project_if_applicable__r.Implementation_Status__c= 'LIVE - CLOSED PROJECT';
                insertCases.add(cas);
            } 

      Test.startTest();
        insert insertCases; 
      Test.stopTest();
    }


}

 
trigger CaseHandlerCountAlert on Case (after insert) {
 	
    //Case trigger that will send email alert when 8 cases are created within 7 days.
    
    String messageToSend;
    List <String> ListOfMessages = new List <String>();
    Set <Id> AcctIds = new Set <Id>();
    String messageBody;

    List < AggregateResult > AggregateResultList = [SELECT AccountId, Account.Name name, COUNT(Id) co
        FROM Case
        WHERE CreatedDate = LAST_N_DAYS:7 AND Id IN :Trigger.New
        GROUP BY AccountId, Account.Name
        HAVING COUNT(Id) >= 8
    ];

    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.Resource_Coordinator_Email__c,
        Parent_Project_if_applicable__r.Client_Advisor_Email__c                      
        FROM Case
        WHERE AccountId IN: AcctIds];
    
	List<Messaging.SingleEmailMessage> lstASingleEmailMessage = new List<Messaging.SingleEmailMessage>();
    List<Messaging.SingleEmailMessage> lstBSingleEmailMessage = new List<Messaging.SingleEmailMessage>();

    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') {
         
            String messageBody = accountIdEmailmessageMap.get(cl.AccountId);
                
                List<String> emailaddr = new List<String>();
                emailaddr.add('CustomerSuccessManagers@test.com');
                
            Messaging.SingleEmailMessage mail = new Messaging.SingleEmailMessage();
            mail.setSenderDisplayName('Support');
            mail.setToAddresses(emailaddr);   
            mail.Subject = 'Multiple cases created alert message';
            mail.setPlainTextBody(messageBody);
			lstASingleEmailMessage.add(mail);
                
       }     

    }
           Messaging.SendEmailResult[] r = Messaging.sendEmail(lstASingleEmailMessage);


    else{
            String messageBody = accountIdEmailmessageMap.get(cl.AccountId);		
            
			List<String> emailAdds = new List<String>();
            emailAdds.add(cl.Parent_Project_if_applicable__r.Resource_Coordinator_Email__c);
            emailAdds.add(cl.Parent_Project_if_applicable__r.Client_Advisor_Email__c);
            
            Messaging.SingleEmailMessage amail = new Messaging.SingleEmailMessage();
            amail.SetSenderDisplayName('Support');
            amail.setToAddresses(emailAdds);
            amail.Subject = 'Multiple cases created alert message';
            amail.setPlainTextBody(messageBody);
			lstBSingleEmailMessage.add(amail);

        }		
           
                Messaging.SendEmailResult[] r = Messaging.sendEmail(lstBSingleEmailMessage);
     
}

In an effort to keep both email SendEmail methods out side of a `For-Loop`, I have mixed up my {}.  Any help is appreciated.

 
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`

 
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);
}    

               }

 

Syntax help please.  I am trying to access the fields in my SOQL search.  I am receiving error message:

`System.SObjectException: Invalid field Parent_Project_if_applicable__r.Implementation_status__c for Case`

I verified Relationship name through WorkBench.

My code is:

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){ 
    System.debug(cl.get('Parent_Project_if_applicable__r.Implementation_status__c'));
}

This is a Trigger that will send an email when the same Account has 8 cases created in the last 5 days. I need to create a second SOQL search for the Project__c object.  

What would the second query look like?

System.UnexpectedException: field 'Client_Advisor_Email__c' can not be grouped in a query call

​​​​​​
trigger CaseHandlerCountAlert on Case (after insert) {
    List<AggregateResult> AggregateResultList = [SELECT AccountId, Account.Name name, COUNT(Id) co,
                                    Project__r.Implementation_status__c, Project__r.Client_Advisor_Email__c
                                    FROM Case
                                    WHERE CreatedDate = LAST_N_DAYS:5 AND Id IN :Trigger.New
                                    GROUP BY AccountId, Account.Name
                                    HAVING COUNT(Id)  >= 8];


                for(AggregateResult aggr:AggregateResultList){ 
                        Messaging.SingleEmailMessage message = new Messaging.SingleEmailMessage();

                            if(aggr != Null && Project__r.Implementation_status__c == 'LIVE - TRANSITION'){    
                                 //Set Outgoing Email to Implementation Coordinator
                                 message.toAddresses = new String[] { Project__r.Client_Advisor_Email__c }; 
                            }
                            else if (aggr != Null && Project__r.Implementation_status__c == 'Live - Closed Project'){  
                                 //Private method getAddresses() retrieves email address from Customer_Success_Managers Public Group

                                 message.toAddresses = new String[] { getAddresses() };
                            } 

                        message.Subject = 'Subject Test Message';
                        message.PlainTextBody = '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')];

    List<String> emailString = new List<String>();

    for(User u: UserList){
        emailstring.add(u.email);
    }   
    return (emailString);
    }    
}

 
The field,  Milestone1_Project__c.Implementation_status__c,  is a Picklist in my If/Else statement used for comparison.  To my understanding I would treat it as a String.  However I am receiving:
Comparison arguments must be compatible types: Schema.SObjectField, String
 
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' };
                            }

 
Help with syntax for 2 WHERE Clauses please.
 
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 AND Id IN :Trigger.New
                                    GROUP BY AccountId, Account.Name
                                    HAVING COUNT(Id)  >= 8
                                    ];

 
Inside the Developer Console, I am receiving the error:
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);
    }    
}

 
Account - Standard Object
Case - Child of Account
Milestone__Project__c - Child of Case

The After-Insert Trigger will send an email message anytime an account has 8 cases or more created in a 5 day period.  The email will be sent to one of two addresses (depending on Project.status).  How do I access the Milestone__Project__c.Status field?  I cannot get the syntax correct.
 
public class CaseHandlerCountAlert{
public static void CaseCounter(){

    List<AggregateResult> AggregateResultList = [SELECT AccountId, Account.Name name, COUNT(Id) co, (Id FROM Milestone1_Project__c mi)
                                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){ 

                    Messaging.SingleEmailMessage message = new Messaging.SingleEmailMessage();
                        if((aggr.get(mi.status) == "Transition"){    // If Status = Transition
                            // Set Outgoing Email to Implementation Coordinator "Implementation.Consultalt "
                            message.toAddresses = new String[] { Milestone1_Project__c.Client_Advisor_Email__c };
                        }
                        else if ((aggr.get(mi.status) == "Live"){  // If Status equals "Live" - Out Of Transition
                            // Private method retrieves email address from Customer Success Managers
                            message.toAddresses = new String[] { getAddresses() };
                        } 
                            // Set Email Template Id
                    //EmailTemplate templateId = [Select id from EmailTemplate where name = 'Template Name'];  
                    //mail.setTemplateID(templateId.Id);
                    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, isactive, profile.name, userrole.name, usertype
                    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);
                // System.debug(u.email);
            }   
            //System.debug('The list ' + emailstring);
            return (emailString);
            }    
            }

 
I am writing an after-insert trigger on the Case object.  I am looking to send an email to one of two people depending on a field that is a child of the Account object.  A sibling to Case.  In my journey I have found that it is not possible to query a sibling (correct me if I'm wrong).  So I've decided,  once I have the Case, I will take the AccountId and do all of my logic and querys from there.

CustObject_Chld2Acct.fieldname - Child to Account, sibling to Contact
 
List<AggregateResult> AggregateResultList = [SELECT AccountId, Account.Name name, COUNT(Id) co, 
                                    FROM Case
                                    WHERE CreatedDate = LAST_N_DAYS:5
                                    GROUP BY AccountId, Account.Name
                                    HAVING COUNT(Id)  >= 8];
                       
        Set<Id> accIdSet = new Set<Id>();
        for(Case c: AggregateResultList) {
        if(c.AccountId != null) {
           System.debug(c.AccountId);
           // Now i have the Account ID, what do I do?  
           //Need to access fields in Account Object (Parent)
           //Need to access fields in CustObject_Chld2Acct          
        }

 

I am trying to find the number of Accounts with 8 cases created in the last 5 days.  And I need to bring in another field 'Implementation_Status__c' from Milestone1_Project__c.


Account -Parent
Case - Child to Account
Milestone1_Project__c - Child to Account



         Account
         /         \
Case          Milestone1_Proect__c
 
List<AggregateResult> AggregateResultList = [SELECT AccountId, Account.Name name, COUNT(Id) co, Account.Milestone1_Project__c status1
                                    FROM Case
                                    WHERE CreatedDate = LAST_N_DAYS:5
                                    GROUP BY AccountId, Account.Name
                                    HAVING COUNT(Id)  >= 8];

 
Just wondering if anyone came across any managed apps or anything worth note regarding integrations during testing for TLS 1.2?
My company's org has about five triggers more than one existing (after insert, after edit).  I am about to create an (after insert) trigger.  Suggestions as to how I would consolidate or should I create my trigger and add to the pile.  If I should consolidate, how would that look?
Is there a way to run a SOQL search for number of cases ran in 40 hours.  My org is looking to send a notification via email anytime an Account has created 8 or more cases within a 40 hour period. 

I am aware that I can use Last_N_Days, just wondering if there is a way to use hours.
 
Is there a place in SETUP or is this something individually I need to search out for each?

I have zero endpoints listed in 'Auth. Providers' in Setup, so I don't believe I have any callouts in APEX.  Also, the vast majority of my production org APEX classes are from managed packages.  I am just looking to not be surprised when TLS 1.1 is gone.
At a lost, I don't know where to start on the testing for this Class.  I don't know the next steps.  Any assistance moving on with the test for this class is appreciated.
 
public class caseTriggerHandlerCount{
    public static void CaseCounter(){

        List<AggregateResult> AggregateResultList = [SELECT AccountId, Account.Name name, COUNT(Id) co
                            FROM Case
                            WHERE CreatedDate = LAST_N_DAYS:50
                            GROUP BY AccountId, Account.Name
                            HAVING COUNT(Id)  >=1];

        for(AggregateResult aggr:AggregateResultList){ 
                
                    // Send Email to Implementation Coordinator
                Messaging.SingleEmailMessage message = new Messaging.SingleEmailMessage();
                    message.toAddresses = new String[] { 'test@test.com' };   
                    message.subject = 'Subject Test Message';
                    message.plainTextBody = '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'));
            
            
        }

} 

}

I have created a Test Factory:
 
@isTest
public class TestDataFactoryCases {
    public static List<Case> createCasesData(Integer numConts) {
        List<Case> lConts = new List<Case>();
        
        for(Integer i=0;i<numConts;i++) {
            Case cse = new Case();
                    cse.status = 'Escalated';
                    cse.origin = 'Community';
                    cse.AccountId = '0013000000qLB9MAAW';
                    cse.Description = 'test ' + i;
            lConts.add(cse);
        }
        insert lConts;

        return lConts;
    }
}

My test Class So far:
 
@isTest
private class TestCaseCountAlert {
    @isTest static void TestPositiveResult() {
        // Test data setup
        
        Case[] cases = TestDataFactoryCases.createCasesData(10);
        
        // Perform test
        Test.startTest();
        
        Test.stopTest();
        
        
    }        
}

​​​​​​​
To find my TLS 1.1 logins I ran the SOQL search and followed instuctions from:

https://help.salesforce.com/articleView?id=000322198&type=1&mode=1&language=en_US

I received no records found:

User-added imageDoes this mean, I don't have any issues with the update?  Anything else I should check?
I am receiving the error:
Unexpected file found in package directory:
When I try to deploy a class that I have just created.  The file is saved in the /force-app/main/default/classes/Case_Trigger_Alert_Count.

I have also noticed that in the 'Problems' tab, I have the message:
The sourcepath ".../force-app/main/default/classes/Case_Trigger_Alert_Count" is not a valid source file path.  SourcePathInvalid [1,1]

The filename of the file I have just created and attempting to deploy is 'Case_Trigger_Alert_Count"
What am I missing to be able to deploy to my Sandbox?
I would like to send an email anytime an account has created 8 cases in the last 8 days.  The email is sending, but within the email, the AccountId (id) is showing.  How would I get the much more readable Account.Name field to show.   
Line: 1, Column: 44
Field must be grouped or aggregated: Name
 
List<AggregateResult> AggregateResultList =[SELECT AccountId, Account.name, COUNT(Id) co
					    FROM Case
					    WHERE CreatedDate = LAST_N_DAYS:8
					    GROUP BY AccountId
					    HAVING COUNT(Id) > 1];

	for(AggregateResult aggr:AggregateResultList){ 
   		 
      		  //Send Email to Implementation Coordinator
  		  Messaging.SingleEmailMessage message = new Messaging.SingleEmailMessage();
   		 message.toAddresses = new String[] { 'test@test.com' };   
   		 message.subject = 'Subject Test Message';
   		 message.plainTextBody = 'Account name: ' + (id)aggr.get('AccountId') + ' 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);
    
  		  if (results[0].success) {
    		    System.debug('The email was sent successfully.');
   		 } else {
    		    System.debug('The email failed to send: ' + results[0].errors[0].message);
   		 }     
    	     
    }

 
I am receiving the error:
Unexpected file found in package directory:
When I try to deploy a class that I have just created.  The file is saved in the /force-app/main/default/classes/Case_Trigger_Alert_Count.

I have also noticed that in the 'Problems' tab, I have the message:
The sourcepath ".../force-app/main/default/classes/Case_Trigger_Alert_Count" is not a valid source file path.  SourcePathInvalid [1,1]

The filename of the file I have just created and attempting to deploy is 'Case_Trigger_Alert_Count"
What am I missing to be able to deploy to my Sandbox?
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`

 
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);
}    

               }

 

Syntax help please.  I am trying to access the fields in my SOQL search.  I am receiving error message:

`System.SObjectException: Invalid field Parent_Project_if_applicable__r.Implementation_status__c for Case`

I verified Relationship name through WorkBench.

My code is:

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){ 
    System.debug(cl.get('Parent_Project_if_applicable__r.Implementation_status__c'));
}
The field,  Milestone1_Project__c.Implementation_status__c,  is a Picklist in my If/Else statement used for comparison.  To my understanding I would treat it as a String.  However I am receiving:
Comparison arguments must be compatible types: Schema.SObjectField, String
 
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' };
                            }

 
Help with syntax for 2 WHERE Clauses please.
 
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 AND Id IN :Trigger.New
                                    GROUP BY AccountId, Account.Name
                                    HAVING COUNT(Id)  >= 8
                                    ];

 
Account - Standard Object
Case - Child of Account
Milestone__Project__c - Child of Case

The After-Insert Trigger will send an email message anytime an account has 8 cases or more created in a 5 day period.  The email will be sent to one of two addresses (depending on Project.status).  How do I access the Milestone__Project__c.Status field?  I cannot get the syntax correct.
 
public class CaseHandlerCountAlert{
public static void CaseCounter(){

    List<AggregateResult> AggregateResultList = [SELECT AccountId, Account.Name name, COUNT(Id) co, (Id FROM Milestone1_Project__c mi)
                                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){ 

                    Messaging.SingleEmailMessage message = new Messaging.SingleEmailMessage();
                        if((aggr.get(mi.status) == "Transition"){    // If Status = Transition
                            // Set Outgoing Email to Implementation Coordinator "Implementation.Consultalt "
                            message.toAddresses = new String[] { Milestone1_Project__c.Client_Advisor_Email__c };
                        }
                        else if ((aggr.get(mi.status) == "Live"){  // If Status equals "Live" - Out Of Transition
                            // Private method retrieves email address from Customer Success Managers
                            message.toAddresses = new String[] { getAddresses() };
                        } 
                            // Set Email Template Id
                    //EmailTemplate templateId = [Select id from EmailTemplate where name = 'Template Name'];  
                    //mail.setTemplateID(templateId.Id);
                    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, isactive, profile.name, userrole.name, usertype
                    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);
                // System.debug(u.email);
            }   
            //System.debug('The list ' + emailstring);
            return (emailString);
            }    
            }

 
To find my TLS 1.1 logins I ran the SOQL search and followed instuctions from:

https://help.salesforce.com/articleView?id=000322198&type=1&mode=1&language=en_US

I received no records found:

User-added imageDoes this mean, I don't have any issues with the update?  Anything else I should check?
I would like to send an email anytime an account has created 8 cases in the last 8 days.  The email is sending, but within the email, the AccountId (id) is showing.  How would I get the much more readable Account.Name field to show.   
Line: 1, Column: 44
Field must be grouped or aggregated: Name
 
List<AggregateResult> AggregateResultList =[SELECT AccountId, Account.name, COUNT(Id) co
					    FROM Case
					    WHERE CreatedDate = LAST_N_DAYS:8
					    GROUP BY AccountId
					    HAVING COUNT(Id) > 1];

	for(AggregateResult aggr:AggregateResultList){ 
   		 
      		  //Send Email to Implementation Coordinator
  		  Messaging.SingleEmailMessage message = new Messaging.SingleEmailMessage();
   		 message.toAddresses = new String[] { 'test@test.com' };   
   		 message.subject = 'Subject Test Message';
   		 message.plainTextBody = 'Account name: ' + (id)aggr.get('AccountId') + ' 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);
    
  		  if (results[0].success) {
    		    System.debug('The email was sent successfully.');
   		 } else {
    		    System.debug('The email failed to send: ' + results[0].errors[0].message);
   		 }     
    	     
    }

 
Hello all,

I am trying to write a batch class (MY FIRST EVER), to take in the AsyncApexJob object and create a csv file of the errors and send to an email address.  I'm sure that some of my syntax is not correct (I would appreciate any input), but I can't even execute to see if it works.  I am receiving the above message when I open a second anonymous window and enter:

AriaBatchErrors objClass=new AriaBatchErrors();
Database.executeBatch(objClass);


So that I can execute:

global class AriaBatchErrors implements Database.Batchable<Sobject>
{
    global string[] email=new String[] {'myEmail@address.com'};
    string[] Lines;
    //start method
    global Database.QueryLocator start(Database.BatchableContext BC)
    {
        lines = new String[0];
        return Database.getQueryLocator('SELECT Id, Status, NumberOfErrors, JobItemsProcessed,TotalJobItems, CreatedBy.Email FROM AsyncApexJob WHERE NumberOfErrors > 0');

    }

    //execute
    global void execute(Database.BatchableContext BC, List<String> scope)
    {
        // process
           for(String record: scope) 
        {
        String line = '';
        // header row
        if ( lines.size() == 0 ) {
            line = 'ID, Status, Number of Errors, Job Items Processed, Total Job Items, Created By';
            lines.add(line);
        }
        else {
            // build csv lines here
            line +='"' + record.get('Id')  +'"'
            +',' + '"' + record.get('Status') + '"'
            +',' + '"' + record.get('NumberOfErrors') +'"'
            +',' + '"' + record.get('JobItemsProcessed') + '"'
            +',' + '"' + record.get('TotalJobItems') + '"' 
            +',' + '"' + record.get('CreatedBy.Email') + '"'   ;               
            lines.add(line);

            system.debug('Line No >>> ' + line); 
        }
         }  // end of for loop   
        
    }


    //finish
    global void finish (Database.BatchableContext BC)
    {
        Messaging.SingleEmailMessage mail=new Messaging.SingleEmailMessage();
        AsyncApexJob a =[select a.TotalJobItems,a.Status,a.NumberOfErrors,a.JobItemsProcessed,a.ExtendedStatus,a.createdById,a.completedDate from AsynchApexJob];
        System.debug('Job Id')+BC.getJobId());
        mail.ToAddreses(email);
        mail.setSenderDisplayName('Apex Batch Processing Errors');
        mail.setSubject('Batch Errors');
        mail.setPlainTextBody('This will be the body of the email' + a.TotalJobItems + 'batches with '+ a.NumberOfErrors);
    }
}

Please help, I am so so new. 

Timothy