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
Rajesh SFDCRajesh SFDC 

how to write test class for batch apex:

i am getting an error Error: Compile Error: Constructor not defined: [SendeMailinBatch].<Constructor>(LIST<CampaignMember>) at line 26 column 2
@isTest(seealldata=true)
public class  testSendeMailinBatch
{

Public static testMethod void m3()


Campaign cp=new Campaign();
cp.EndDate=system.today();
cp.StartDate=system.today();
cp.isActive=TRUE;
CP.Type='Email';
cp.Status='planned';
cp.Reply_To__c='test@tanture.com';
cp.From_eMail__c='rajesh@tandture.com';
insert cp;
//list<Campaign> cplist=new list<Campaign>();
CampaignMember cm=new CampaignMember();
//cm.Campaign=cp.id;
insert cm;
cm=[select id  from campaignmember where id = :cp.id]; 
insert cm;
list<CampaignMember> cmlist=new list<CampaignMember>();
//set<CampaignMember> cmlis=new set<CampaignMember>();
cmlist.add(cm);
SendeMailinBatch sb=new SendeMailinBatch(cmlist);
     
        Test.startTest();
        Database.executeBatch(sb,1);
        Test.stopTest();
       
    }
 
 
  }
Sagarika RoutSagarika Rout
I think you have missed of declaring parameterised constructure in your class , which will take list as a parameter
justin_sfdcjustin_sfdc

Hi there,
Could you post your batch class so that we can help you more.
 

From what i get, when you are creating a new campaign member, you need to assign the id of that member to the particular campaign that you created then put that campaignMember in the list with the running the loop on the campaingMember. I think that should work.
campaign cp = new campaign();
...
..
insert cp;
CampaignMember mem1= new CampaignMember(campaignId=cp.id);
insert mem1;

List<CampaignMember> cmlis= [SELECT CampaignId, Id, Campaign.reply_to__c, campaign.from_email__c FROM CampaignMember where id =:mem1.id ];
SendeMailinBatch sb=new SendeMailinBatch(cmlist);
    
        Test.startTest();
        Database.executeBatch(sb,1);
        Test.stopTest();
      
    }

Hope that helped.
 

Thanks,
justin~sfdc