The same rules apply; you'll want to create exactly one record so that your code will run all the way through the loop, then verify after Test.stopTest() that a single snapshot record was created as a result.
Database.getQueryLocator returns the List.
So you just need to assign the the list of values like below : -
global Database.QueryLocator start(Database.BatchableContext bc) {
query = SELECT OwnerId, Owner.Name, Execution_Type__c, Child_Campaign_Status__c, Campaign_CCC_Manager__c, Execution_Start_Date__c, ParentId, Campaign_Code__c, Parent.Campaign_Type__c, (SELECT OwnerId, Contact_Id__c, Special_Flag_to_Include__c, Special_flag_to_Exclude__c, Delinquency_Flag__c, MBF_Anti_Social_flag__c, Payment_Suspended_Flag__c, Auto_creation_of_tasks__c, Auto_creation_of_leads__c, Auto_creation_of_DM_requests__c, Address__r.Address_Type__c, Preferred_Dealer__c, Campaign_ID__r.Parent.Campaign_Type__c, Zip_Code_Finance__c, Zip_Code__c, Campaign_ID__r.OwnerId FROM Campaign_Members1__r) FROM Campaign WHERE RecordType.DeveloperName = 'Campaign_Executiono'
return Database.getQueryLocator(query);
}
then declare the execute method like below : -
global void execute(Database.BatchableContext ctx, List<Sobject> scope){
List<Campaign> lst_Camp = (List<Campaign>)scope;
//then do your changes based on your logic with **lst_Camp** records
}
it will solve your purpose.
Best Answer
Generally, you use Test.startTest() and Test.stopTest() to test batchable classes, like so:
The only drawback is that we're limited to a single batch using this method, so that's usually why you'll see either a custom query or custom limit:
Some people prefer to pass in a SOQL string variable, but that's just a bad idea. You should prefer inline static query statements when possible.