You need to sign in to do that
Don't have an account?

Batch Class error
hello i have written below batch class but when its running its giving an error : System.StringException: Invalid id: u.id at line number 16
global class batchleadUpdate implements Database.Batchable<sObject>
{
global Database.QueryLocator start(Database.BatchableContext BC)
{
User u = [select Id from User where Profile.Name='System Administrator' Limit 1];
String query = 'SELECT Id,Name,Status ,OwnerId FROM Lead WHERE Status != \'Closed - Converted\' AND CreatedDate < LAST_N_DAYS:30';
return Database.getQueryLocator(query);
}
global void execute(Database.BatchableContext BC, List<Lead> scope)
{
for(Lead le : scope)
{
le.OwnerId = 'u.Id' ;
}
update scope;
}
global void finish(Database.BatchableContext BC)
{
}
}
can any one help me by telling what i did wrong . will be of great help
Thanks all
global class batchleadUpdate implements Database.Batchable<sObject>
{
global Database.QueryLocator start(Database.BatchableContext BC)
{
User u = [select Id from User where Profile.Name='System Administrator' Limit 1];
String query = 'SELECT Id,Name,Status ,OwnerId FROM Lead WHERE Status != \'Closed - Converted\' AND CreatedDate < LAST_N_DAYS:30';
return Database.getQueryLocator(query);
}
global void execute(Database.BatchableContext BC, List<Lead> scope)
{
for(Lead le : scope)
{
le.OwnerId = 'u.Id' ;
}
update scope;
}
global void finish(Database.BatchableContext BC)
{
}
}
can any one help me by telling what i did wrong . will be of great help
Thanks all
Change your execute method to You could remove query on user
User u = [select Id from User where Profile.Name='System Administrator' Limit 1];
from start method