+ Start a Discussion
SFDC n12SFDC n12 

test class help

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:con.id];

        // verify if target tasks etc are created successfully
       System.assert(createdTasks);
    }
 
}


kindly help me


Thanks in Advance
Best Answer chosen by SFDC n12
Jakub OrackiJakub Oracki
You should put boolean expression as an argument to assert method.
You can do the following:

Task[] createdTasks = [Select Id,WhoId,Subject,ActivityDate,Description  from Task Where Subject ='Bounceback Correction'AND WhoId = :con.id];
        // verify if target tasks etc are created successfully
         System.assert(createdTasks.size()>0);

All Answers

Jakub OrackiJakub Oracki
Hi,

you schould use equals sign instead:

Task createdTasks = [Select Id,WhoId ,OwnerId ,Subject ,ActivityDate,Description  from Task Where WhoId =:con.id];

or create LIST or SET and put it on the end of query 

Set<Id> contactsSet = new Set<Id>();
contactsSet.add(con.Id);

Task createdTasks = [Select Id,WhoId ,OwnerId ,Subject ,ActivityDate,Description  from Task Where WhoId IN:contactsSet];

Regards
Jakub
SFDC n12SFDC n12
Hi,

Thanks it worked, another doubt is i am trying to add a system.assert statement below my query


Task createdTasks = [Select Id,WhoId,Subject,ActivityDate,Description  from Task Where Subject ='Bounceback Correction'AND WhoId = :con.id];
        // verify if target tasks etc are created successfully
          //System.assert(createdTasks);

but it didnt work


Error: Compile Error: Method does not exist or incorrect signature: System.assert(SOBJECT:Task) at line 44 column 11

getting the above error

Please let me know hw to add the system.assert statement in my code

Jakub OrackiJakub Oracki
You should put boolean expression as an argument to assert method.
You can do the following:

Task[] createdTasks = [Select Id,WhoId,Subject,ActivityDate,Description  from Task Where Subject ='Bounceback Correction'AND WhoId = :con.id];
        // verify if target tasks etc are created successfully
         System.assert(createdTasks.size()>0);
This was selected as the best answer
SFDC n12SFDC n12
thanks dude, it worked