function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
sandeep kumar 44sandeep kumar 44 

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
Shashikant SharmaShashikant Sharma
You are assigning a String to Id field . 

Change your execute method to
global void execute(Database.BatchableContext BC, List<Lead> scope)
    {
             User u = [select Id from User where Profile.Name='System Administrator' Limit 1];
         for(Lead le : scope)
         {
             le.OwnerId = u.Id  ;           
         }
         update scope;
    }
You could remove query on user
User u = [select Id from User where Profile.Name='System Administrator' Limit 1];
from start method