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
Ramkumar MurugesanRamkumar Murugesan 

Schedule job apex class is not update the records

Hello Friends,

The below apex class is not updating the records properly. Can you please the same
 
global class UserLicense implements Database.Batchable<Sobject>{
    global String Query;

 global Database.QueryLocator start(Database.BatchableContext BC)
    {   
    Query='SELECT Id,IsActive,Market_NES__c,Profile.UserLicense.Name, Name FROM User WHERE IsActive = true';//u can add fields and put where conditions based on requirement
    return Database.getQueryLocator(Query);
    }
 
    global void execute(Database.BatchableContext BC, List<Sobject> scope)
    {
    List <Market_Info_NES__c> ml = new list<Market_Info_NES__c> ();
    ml=Database.Query('SELECT Id,Market_NES__c,Number_of_Admin_Licences_NES__c,Number_of_platform_Licences_NES__c FROM Market_Info_NES__c');
    for(User s : (list<User>)scope)
    {
        Market_Info_NES__c a = new Market_Info_NES__c();
        Integer countAdminLicense =0; 
        Integer countPlatformLicense =0;
        if (a.Market_NES__c==s.Market_NES__c)
        {
            if (s.Profile.UserLicense.Name !='Salesforce Platform') {
                a.Number_of_Admin_Licences_NES__c = countAdminLicense++ ;
            }
            else 
            {   a.Number_of_platform_Licences_NES__c = countPlatformLicense++ ;
            }
        }        
        
        ml.add(a);
    }
    update ml;
    }
 
    global void finish(Database.BatchableContext BC)
    {
             
    }

    
}

 
Balaji BondarBalaji Bondar
Ramkumar,
This condition will not meet at any time  a.Market_NES__c==s.Market_NES__c as you are creating Market_Info_NES__c a = new Market_Info_NES__c(); as a new object.
Please check your code/logic.
 
Ramkumar MurugesanRamkumar Murugesan
Can you please correct it for me