0

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

1

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.

0

Execute method takes the following:

  1. A reference to the Database.BatchableContext object.
  2. A list of sObjects, such as List, or a list of parameterized types. If you are using a Database.QueryLocator, use the returned list.

    global Database.QueryLocator start(Database.BatchableContext BC){
    return Database.getQueryLocator(query);
    }
    global void execute(Database.BatchableContext BC, List<sObject> scope){
     List<Campaign> CampaignList=new List<Campaign> ();
     for(sobject s : scope)
       CampaignList.add((Campaign)s);
    
     //OR List<Campaign> CampaignList = (List<Campaign>)scope;
    }
     global void finish(Database.BatchableContext BC){}
    

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.