• Anoop Patel 24
  • NEWBIE
  • 10 Points
  • Member since 2017

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 1
    Questions
  • 1
    Replies
I'm trying to count the number of accounts a user owns as well as stamping the last login date in a custom field within the same class but I'm receiving the error below on my scheduled class.

Invalid integer: common.apex.runtime.impl.SObjectList@c21a4303

My class...

global class LoginDateClass implements Schedulable{

    global void execute(SchedulableContext SC){
    
    list<user> userList = [SELECT Id,Total_Number_of_Accounts__c,LastLoginDate FROM User WHERE IsActive = TRUE LIMIT 9999];
    LIST<AggregateResult> NoOfAccounts = [SELECT OwnerId u, count(Id) a FROM Account WHERE CoreAccounts__Inactive__c = FALSE  AND OwnerId in :userList GROUP BY OwnerId];
    
    
    for(User user : userList){
        user.Last_Login__c = user.LastLoginDate;
        user.Total_Number_of_Accounts__c  = integer.valueOf(NoOfAccounts);
        }
        update userList;   
      }
}
I'm trying to count the number of accounts a user owns as well as stamping the last login date in a custom field within the same class but I'm receiving the error below on my scheduled class.

Invalid integer: common.apex.runtime.impl.SObjectList@c21a4303

My class...

global class LoginDateClass implements Schedulable{

    global void execute(SchedulableContext SC){
    
    list<user> userList = [SELECT Id,Total_Number_of_Accounts__c,LastLoginDate FROM User WHERE IsActive = TRUE LIMIT 9999];
    LIST<AggregateResult> NoOfAccounts = [SELECT OwnerId u, count(Id) a FROM Account WHERE CoreAccounts__Inactive__c = FALSE  AND OwnerId in :userList GROUP BY OwnerId];
    
    
    for(User user : userList){
        user.Last_Login__c = user.LastLoginDate;
        user.Total_Number_of_Accounts__c  = integer.valueOf(NoOfAccounts);
        }
        update userList;   
      }
}