You need to sign in to do that
Don't have an account?
Ravi23
Refine the query when we search in batch Class
Hi All,
Below is my Batch class. Is that always we require to pull complete records in databse in query field or can we filter using where condition. If we can filter can some one help me on this.
global class batchContactAccountNameUpdate implements Database.Batchable<sObject> {
global Database.QueryLocator start(Database.BatchableContext BC) {
String query = 'SELECT Id, AccountId FROM Contact ';
return Database.getQueryLocator(query);
}
global void execute(Database.BatchableContext BC, List<Contact> scope) {
for(Contact c : scope)
{
if(c.AccountId==null){
c.AccountId = '0011900000BiZzn';
}
}
update scope;
}
global void finish(Database.BatchableContext BC) {
}
}
Below is my Batch class. Is that always we require to pull complete records in databse in query field or can we filter using where condition. If we can filter can some one help me on this.
global class batchContactAccountNameUpdate implements Database.Batchable<sObject> {
global Database.QueryLocator start(Database.BatchableContext BC) {
String query = 'SELECT Id, AccountId FROM Contact ';
return Database.getQueryLocator(query);
}
global void execute(Database.BatchableContext BC, List<Contact> scope) {
for(Contact c : scope)
{
if(c.AccountId==null){
c.AccountId = '0011900000BiZzn';
}
}
update scope;
}
global void finish(Database.BatchableContext BC) {
}
}
you can control the batch size while invoking this class like below
String query = 'SELECT Id, AccountId,Type__C FROM Contact where Type__c=:Asian Entities';
And I am not getting error in code but when I run the batch class I get unexpected token Entities
This time no error when I run the batch but not even one record was processed in the batch. Which is indicating the query was not realized.
can you run the above query from dataloader/devconsole and see what is being returned ?