Skip to main content
formatting code, removing irrelevant tags
Source Link
Derek F
  • 64.1k
  • 15
  • 55
  • 104

Created data in test class with User but as scope getting different user with Name system. Not the which iI have created in test class

 for(user u: scope){
Inventy it=  [select ID from Inventy where  IRole__c =: u.UserCategory__c LIMIT 1];
}
for(user u: scope){
    Inventy it =  [select ID from Inventy where  IRole__c = :u.UserCategory__c LIMIT 1];
}

Getting error List has no rows for assignment. In test class. Created this user for scope.

 Integer RandomId1=Integer.valueOf(Math.rint(Math.random()*1100000)); 
                    String uniqueName1=orgId+dateString+RandomId1;
                 User uu1=new User(firstname = 'ABC', 
                 lastName = 'XYZ', 
                 Isactive = true,
                 email = uniqueName1 + '@test' + orgId + '.org', 
                 Username = uniqueName1 + '@test' + orgId + '.org', 
                 EmailEncodingKey = 'ISO-8859-1', 
                 Alias = uniqueName1.substring(18, 23), 
                 TimeZoneSidKey = 'America/Los_Angeles', 
                 LocaleSidKey = 'en_US', 
                 LanguageLocaleKey = 'en_US', 
                 ProfileId = pf.Id,
                 UserCategory__c = 'Junior'        
                ); 

List has no rows for assignment In test class. Created this user for scope.

Integer RandomId1 = Integer.valueOf(Math.rint(Math.random()*1100000)); 
String uniqueName1 = orgId + dateString + RandomId1;
User uu1 = new User(
    firstname = 'ABC', 
    lastName = 'XYZ', 
    Isactive = true,
    email = uniqueName1 + '@test' + orgId + '.org', 
    Username = uniqueName1 + '@test' + orgId + '.org', 
    EmailEncodingKey = 'ISO-8859-1', 
    Alias = uniqueName1.substring(18, 23), 
    TimeZoneSidKey = 'America/Los_Angeles', 
    LocaleSidKey = 'en_US', 
    LanguageLocaleKey = 'en_US', 
    ProfileId = pf.Id,
    UserCategory__c = 'Junior'        
);

Created data in test class with User but as scope getting different user with Name system. Not the which i have created in test class

 for(user u: scope){
Inventy it=  [select ID from Inventy where  IRole__c =: u.UserCategory__c LIMIT 1];
}

Getting error List has no rows for assignment. In test class. Created this user for scope.

 Integer RandomId1=Integer.valueOf(Math.rint(Math.random()*1100000)); 
                    String uniqueName1=orgId+dateString+RandomId1;
                 User uu1=new User(firstname = 'ABC', 
                 lastName = 'XYZ', 
                 Isactive = true,
                 email = uniqueName1 + '@test' + orgId + '.org', 
                 Username = uniqueName1 + '@test' + orgId + '.org', 
                 EmailEncodingKey = 'ISO-8859-1', 
                 Alias = uniqueName1.substring(18, 23), 
                 TimeZoneSidKey = 'America/Los_Angeles', 
                 LocaleSidKey = 'en_US', 
                 LanguageLocaleKey = 'en_US', 
                 ProfileId = pf.Id,
                 UserCategory__c = 'Junior'        
                ); 

Created data in test class with User but as scope getting different user with Name system. Not the which I have created in test class

for(user u: scope){
    Inventy it =  [select ID from Inventy where  IRole__c = :u.UserCategory__c LIMIT 1];
}

Getting error

List has no rows for assignment In test class. Created this user for scope.

Integer RandomId1 = Integer.valueOf(Math.rint(Math.random()*1100000)); 
String uniqueName1 = orgId + dateString + RandomId1;
User uu1 = new User(
    firstname = 'ABC', 
    lastName = 'XYZ', 
    Isactive = true,
    email = uniqueName1 + '@test' + orgId + '.org', 
    Username = uniqueName1 + '@test' + orgId + '.org', 
    EmailEncodingKey = 'ISO-8859-1', 
    Alias = uniqueName1.substring(18, 23), 
    TimeZoneSidKey = 'America/Los_Angeles', 
    LocaleSidKey = 'en_US', 
    LanguageLocaleKey = 'en_US', 
    ProfileId = pf.Id,
    UserCategory__c = 'Junior'        
);
added 90 characters in body
Source Link
sfdcfox
  • 501.7k
  • 21
  • 473
  • 828

I have a batch job with scope as List of User with Id,Name and one Custom field.

Created data in test class with User but as scope getting different user with Name system. Not the which i have created in test class

Batch job scope . start method query = 'SELECT Id,Name,UserCategory__c from User WHERE IsActive = TRUE LIMIT 1';

query = 'SELECT Id,Name,UserCategory__c from User WHERE IsActive = TRUE LIMIT 1';

Execute method. for(user u: scope){ Inventy it= [select ID from Inventy where IRole__c =: u.UserCategory__c LIMIT 1]; }

 for(user u: scope){
Inventy it=  [select ID from Inventy where  IRole__c =: u.UserCategory__c LIMIT 1];
}

Getting error List has no rows for assignment. In test class. Created this user for scope.

Integer RandomId1=Integer.valueOf(Math.rint(Math.random()*1100000)); String uniqueName1=orgId+dateString+RandomId1; User uu1=new User(firstname = 'ABC', lastName = 'XYZ', Isactive = true, email = uniqueName1 + '@test' + orgId + '.org', Username = uniqueName1 + '@test' + orgId + '.org', EmailEncodingKey = 'ISO-8859-1', Alias = uniqueName1.substring(18, 23), TimeZoneSidKey = 'America/Los_Angeles', LocaleSidKey = 'en_US', LanguageLocaleKey = 'en_US', ProfileId = pf.Id, UserCategory__c = 'Junior'
);

 Integer RandomId1=Integer.valueOf(Math.rint(Math.random()*1100000)); 
                    String uniqueName1=orgId+dateString+RandomId1;
                 User uu1=new User(firstname = 'ABC', 
                 lastName = 'XYZ', 
                 Isactive = true,
                 email = uniqueName1 + '@test' + orgId + '.org', 
                 Username = uniqueName1 + '@test' + orgId + '.org', 
                 EmailEncodingKey = 'ISO-8859-1', 
                 Alias = uniqueName1.substring(18, 23), 
                 TimeZoneSidKey = 'America/Los_Angeles', 
                 LocaleSidKey = 'en_US', 
                 LanguageLocaleKey = 'en_US', 
                 ProfileId = pf.Id,
                 UserCategory__c = 'Junior'        
                ); 

But still while debuggig saw that this user is not considered in scope. Instead of this different user created with Name System.

I have a batch job with scope as List of User with Id,Name and one Custom field.

Created data in test class with User but as scope getting different user with Name system. Not the which i have created in test class

Batch job scope . start method query = 'SELECT Id,Name,UserCategory__c from User WHERE IsActive = TRUE LIMIT 1';

Execute method. for(user u: scope){ Inventy it= [select ID from Inventy where IRole__c =: u.UserCategory__c LIMIT 1]; }

Getting error List has no rows for assignment. In test class. Created this user for scope.

Integer RandomId1=Integer.valueOf(Math.rint(Math.random()*1100000)); String uniqueName1=orgId+dateString+RandomId1; User uu1=new User(firstname = 'ABC', lastName = 'XYZ', Isactive = true, email = uniqueName1 + '@test' + orgId + '.org', Username = uniqueName1 + '@test' + orgId + '.org', EmailEncodingKey = 'ISO-8859-1', Alias = uniqueName1.substring(18, 23), TimeZoneSidKey = 'America/Los_Angeles', LocaleSidKey = 'en_US', LanguageLocaleKey = 'en_US', ProfileId = pf.Id, UserCategory__c = 'Junior'
);

But still while debuggig saw that this user is not considered in scope. Instead of this different user created with Name System.

I have a batch job with scope as List of User with Id,Name and one Custom field.

Created data in test class with User but as scope getting different user with Name system. Not the which i have created in test class

Batch job scope . start method

query = 'SELECT Id,Name,UserCategory__c from User WHERE IsActive = TRUE LIMIT 1';

Execute method.

 for(user u: scope){
Inventy it=  [select ID from Inventy where  IRole__c =: u.UserCategory__c LIMIT 1];
}

Getting error List has no rows for assignment. In test class. Created this user for scope.

 Integer RandomId1=Integer.valueOf(Math.rint(Math.random()*1100000)); 
                    String uniqueName1=orgId+dateString+RandomId1;
                 User uu1=new User(firstname = 'ABC', 
                 lastName = 'XYZ', 
                 Isactive = true,
                 email = uniqueName1 + '@test' + orgId + '.org', 
                 Username = uniqueName1 + '@test' + orgId + '.org', 
                 EmailEncodingKey = 'ISO-8859-1', 
                 Alias = uniqueName1.substring(18, 23), 
                 TimeZoneSidKey = 'America/Los_Angeles', 
                 LocaleSidKey = 'en_US', 
                 LanguageLocaleKey = 'en_US', 
                 ProfileId = pf.Id,
                 UserCategory__c = 'Junior'        
                ); 

But still while debuggig saw that this user is not considered in scope. Instead of this different user created with Name System.

Source Link
SAK
  • 15
  • 1
  • 1
  • 10

Test class for Batch job having User object as scope with Custom field

I have a batch job with scope as List of User with Id,Name and one Custom field.

Created data in test class with User but as scope getting different user with Name system. Not the which i have created in test class

Batch job scope . start method query = 'SELECT Id,Name,UserCategory__c from User WHERE IsActive = TRUE LIMIT 1';

Execute method. for(user u: scope){ Inventy it= [select ID from Inventy where IRole__c =: u.UserCategory__c LIMIT 1]; }

Getting error List has no rows for assignment. In test class. Created this user for scope.

Integer RandomId1=Integer.valueOf(Math.rint(Math.random()*1100000)); String uniqueName1=orgId+dateString+RandomId1; User uu1=new User(firstname = 'ABC', lastName = 'XYZ', Isactive = true, email = uniqueName1 + '@test' + orgId + '.org', Username = uniqueName1 + '@test' + orgId + '.org', EmailEncodingKey = 'ISO-8859-1', Alias = uniqueName1.substring(18, 23), TimeZoneSidKey = 'America/Los_Angeles', LocaleSidKey = 'en_US', LanguageLocaleKey = 'en_US', ProfileId = pf.Id, UserCategory__c = 'Junior'
);

But still while debuggig saw that this user is not considered in scope. Instead of this different user created with Name System.