I think you also need to check the length of FirstName
for(List<Contact> conList :[SELECT Id,FirstName,LastName,Contact_type__c, Commission_Spiff__c
FROM Contact Contact
WHERE ( CreatedDate < 2017-03-09T14:19:25.000Z AND CreatedDate > 2016-12-01T14:19:25.000Z)])
{
for(Contact ob: conList)
{
if(ob.FirstName == NULL || ob.FirstName.trim().length()==0){
ob.FirstName = ob.LastName;
}
}
update conList;
}
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
Just simply run this query in anonymous window and you will get the result. Check code sample below.
Replace query with your query string.