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
SFDC n12SFDC n12 

test class help

Hi,

Please help me to write  a test class for the below trigger

/**
**
**/
trigger AF_processETBouncebacks on et4ae5__IndividualEmailResult__c (after insert) {

   Map<String,String> aeMap = new Map<String,String>();
   List<Case> casesToInsert = new List<Case>();
   List<Task> tasksToInsert = new List<Task>();
   List<et4ae5__IndividualEmailResult__c> bouncedEmails = new List<et4ae5__IndividualEmailResult__c>();
   Map<String,String> acEmailMap = new Map<String,String>();
        
   for (et4ae5__IndividualEmailResult__c bouncedEmail: Trigger.New) {
  
      if (bouncedEmail.et4ae5__HardBounce__c) {
           bouncedEmails.add(bouncedEmail);
       }
   }

   if (bouncedEmails.size() > 0) {
     
      for (et4ae5__IndividualEmailResult__c tempList : [Select et4ae5__Contact__r.AccountId from et4ae5__IndividualEmailResult__c Where Id IN :bouncedEmails]){ 
          acEmailMap.put(tempList.Id,tempList.et4ae5__Contact__r.AccountId);
      }
     
      Map<String, RecordType>  caseRecordTypeMap = AF_DealerCRM_Utility.getRecordTypes('Case'); 
      Map<String,Group> dealerCrmQueueMap = AF_DealerCRM_Utility.getDealerCrmQueue();
      aeMap = AF_DealerCRM_Utility.getAE(acEmailMap.values());
     
      for (et4ae5__IndividualEmailResult__c email: bouncedEmails) {
     
          String acId = acEmailMap.get(email.id);
         
          if (aeMap.containsKey(acId)) { 
             Task tsk = new Task();
             tsk.WhoId = email.et4ae5__Contact__c;
             tsk.OwnerId = aeMap.get(acId); 
             tsk.Subject = 'Bounceback Correction';
             tsk.ActivityDate = date.today()+5;
             tsk.CreatedById = System.Label.ExactTarget_Admin;
             tsk.Description = 'There was a bounceback for this Contact. The email send id : ' + email.et4ae5__SendDefinition__c;
             tasksToInsert.add (tsk);
          }
          else {
              // If no Autofinance AE or Additional AE exists, then create a case and assign to Sales Performance Queue.
              Case cs = new Case();
              cs.AccountId = acId;
              cs.Priority = 'Medium';
              cs.Subject = 'No AE found on Account Team';
              cs.Status = 'New';
              cs.Description = 'Please navigate to the contact on this case to re-assign the task owner';
              cs.ContactId = email.et4ae5__Contact__c;
              cs.Case_related_to__c = 'Contact';
              cs.RecordTypeId = caseRecordTypeMap.get('Sales').Id;
              cs.OwnerId = dealerCrmQueueMap.get('Case Mgmt Sales Performance').Id;
              casesToInsert.add(cs);
          }
            
      }    

      /* New Cases for AE that are not found.*/
      if (casesToInsert.size() > 0 ) {
       
         try {
            AF_DealerCRM_DML_Utility.insert_op(casesToInsert); 
         }
         catch(Exception ex) {
            system.debug('Exception while creating Case' + ex.getMessage());
         }    
      }
     
      /* New Tasks to create for bounced emails */
      if (tasksToInsert.size() > 0) {
     
         try {
             AF_DealerCRM_DML_Utility.insert_op(tasksToInsert); 
         }
         catch(Exception ex) {
             system.debug('Exception while creating Tasks for bounced emails : ' + ex.getMessage());
         }    
           
      } 
   }
 
}



Thanks in Advance
 

Abhinav GuptaAbhinav Gupta
This blog post explain thoroghly how to do that : http://www.shivasoft.in/blog/salesforce/step-by-step-salesforce-tutorial-creating-trigger-and-test-cases-6-of-6/

In general here is a quick pattern

@isTest
public class TriggerTest {
	
	testMethod static void testPostiveCase() {
		Test.startTest();
		// Create a few records to test various scenarios 
		et4ae5__IndividualEmailResult__c [] seedData = new ....
		//... 

		insert seedData;

		Test.stopTest();

		Task createdTasks = [Select Id ..... from Task Where WhoId IN :seedData];
		// verify if target tasks etc are created successfully
		System.assertXXX(createdTasks);

	}
   

}




SFDC n12SFDC n12

I am getting te following error in my code

 Error: Compile Error: IN operator must be used with an iterable expression at line 34 column 116



below is my test class code


@isTest
public class AF_processETBouncebacks{
   
    testMethod static void testProcessBouncebacksTrigger() {
        Test.startTest();
        // Create a few records to test various scenarios
       
       
        contact con = new contact();
        con.LastName ='c';
        insert con;
     
       
        et4ae5__IndividualEmailResult__c emailresult = new et4ae5__IndividualEmailResult__c();
        emailresult.et4ae5__Contact__c =con.id;
        emailresult.et4ae5__Contact__r.AccountId='1803 C/O DLRSHIP LIQUIDATIONS';
        emailresult.et4ae5__DateBounced__c =date.today();
        emailresult.et4ae5__HardBounce__c = true;
        emailresult.et4ae5__Opened__c = true;
        insert emailresult;
       
       
         /*Task tsk = new Task();
         tsk.WhoId =emailresult;
         //tsk.OwnerId = aeMap.get(acId); 
         tsk.Subject = 'Bounceback Correction';
         tsk.ActivityDate = date.today()+5;
         //tsk.CreatedById = System.Label.ExactTarget_Admin;
         tsk.Description = 'There was a bounceback for this Contact. The email send id : ';
         insert tsk;
*/
        Test.stopTest();

        Task createdTasks = [Select Id,WhoId ,OwnerId ,Subject ,ActivityDate,Description  from Task Where WhoId IN:emailresult];
        // verify if target tasks etc are created successfully
       System.assert(createdTasks);

    }
  

}


kindly help me


Thanks in Advance