[SalesForce] illegal assignmet database.querylocator to list

I have a batch class, the return type of start method is 'Database.QueryLocator' and I'm returning the follow:

  global Database.QueryLocator start(Database.BatchableContext bc) {
         string 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);
    }

And the Execute method is like the following :

 global void execute(Database.BatchableContext bc, List<Campaign> scope) {
//Logic 
}

But here I'm getting the above error:

illegal assignment database.getquerylocator to list

Best Answer

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.