Skip to main content
replaced http://salesforce.stackexchange.com/ with https://salesforce.stackexchange.com/
Source Link

Hard to say much without knowing which line fails ;) Is it a compilation error or runtime one? Does it occur in the unit test class or in the batch itself?

captureBatch.query = 'SELECT id, LastLoginDate,LastLoginDate__c FROM User where Id =:u.Id';

I see few problems here...

  1. Dynamic queries can have bind variables but the variable must be completely resolved (no dots, no function calls are allowed). See also the excellent answer to Elegant way to convert Set<Id> into String for Dynamic SOQL IN comparisonElegant way to convert Set<Id> into String for Dynamic SOQL IN comparison
  2. The batch will start in different context. Does the batch run ok when executed outside of unit test? I'm asking because there's a chance by the time you reach that start() the variable binding you've specified will be gone and query will fail. Consider passing Set<Id> to the batch class maybe or create the query as a string without bindings: 'SELECT id, LastLoginDate,LastLoginDate__c FROM User where Id = \' + u.Id + '\'';

Last but not least, you need to fill in more required fields when you insert an user in unit test... Creating a user with DMLCreating a user with DML should be a nice sample (although I like your syntax with initialization list in new User(...) more, wastes less script statements).

Hard to say much without knowing which line fails ;) Is it a compilation error or runtime one? Does it occur in the unit test class or in the batch itself?

captureBatch.query = 'SELECT id, LastLoginDate,LastLoginDate__c FROM User where Id =:u.Id';

I see few problems here...

  1. Dynamic queries can have bind variables but the variable must be completely resolved (no dots, no function calls are allowed). See also the excellent answer to Elegant way to convert Set<Id> into String for Dynamic SOQL IN comparison
  2. The batch will start in different context. Does the batch run ok when executed outside of unit test? I'm asking because there's a chance by the time you reach that start() the variable binding you've specified will be gone and query will fail. Consider passing Set<Id> to the batch class maybe or create the query as a string without bindings: 'SELECT id, LastLoginDate,LastLoginDate__c FROM User where Id = \' + u.Id + '\'';

Last but not least, you need to fill in more required fields when you insert an user in unit test... Creating a user with DML should be a nice sample (although I like your syntax with initialization list in new User(...) more, wastes less script statements).

Hard to say much without knowing which line fails ;) Is it a compilation error or runtime one? Does it occur in the unit test class or in the batch itself?

captureBatch.query = 'SELECT id, LastLoginDate,LastLoginDate__c FROM User where Id =:u.Id';

I see few problems here...

  1. Dynamic queries can have bind variables but the variable must be completely resolved (no dots, no function calls are allowed). See also the excellent answer to Elegant way to convert Set<Id> into String for Dynamic SOQL IN comparison
  2. The batch will start in different context. Does the batch run ok when executed outside of unit test? I'm asking because there's a chance by the time you reach that start() the variable binding you've specified will be gone and query will fail. Consider passing Set<Id> to the batch class maybe or create the query as a string without bindings: 'SELECT id, LastLoginDate,LastLoginDate__c FROM User where Id = \' + u.Id + '\'';

Last but not least, you need to fill in more required fields when you insert an user in unit test... Creating a user with DML should be a nice sample (although I like your syntax with initialization list in new User(...) more, wastes less script statements).

Source Link
eyescream
  • 24.2k
  • 5
  • 59
  • 96

Hard to say much without knowing which line fails ;) Is it a compilation error or runtime one? Does it occur in the unit test class or in the batch itself?

captureBatch.query = 'SELECT id, LastLoginDate,LastLoginDate__c FROM User where Id =:u.Id';

I see few problems here...

  1. Dynamic queries can have bind variables but the variable must be completely resolved (no dots, no function calls are allowed). See also the excellent answer to Elegant way to convert Set<Id> into String for Dynamic SOQL IN comparison
  2. The batch will start in different context. Does the batch run ok when executed outside of unit test? I'm asking because there's a chance by the time you reach that start() the variable binding you've specified will be gone and query will fail. Consider passing Set<Id> to the batch class maybe or create the query as a string without bindings: 'SELECT id, LastLoginDate,LastLoginDate__c FROM User where Id = \' + u.Id + '\'';

Last but not least, you need to fill in more required fields when you insert an user in unit test... Creating a user with DML should be a nice sample (although I like your syntax with initialization list in new User(...) more, wastes less script statements).