You need to sign in to do that
Don't have an account?
ForceRookie
How to create test class of Batch class?
Field API Name Datatype
Contact Contact__c LookUp //field from Opportunity
Awesome Awesome__C CheckBox //field from Contact
Contact Contact__c LookUp //field from Opportunity
Awesome Awesome__C CheckBox //field from Contact
global class BatchAwesomeContact implements Database.Batchable<sObject>{ Map<Id, Contact> conts = new Map<Id, Contact>(); global Database.QueryLocator start(Database.BatchableContext BC) { String Query = 'SELECT Id, Contact__c, Amount, (SELECT Id, FirstName, LastName, Awesome__c FROM Contact) FROM Opportunity WHERE Id IN :conts.keySet()'; return Database.getQueryLocator(Query); } global void execute(Database.BatchableContext BC, List<Opportunity> scope) { for (Opportunity s : scope) { if (s.Contact__c != null) { if (s.Amount >= 500 && !conts.containsKey(s.Contact__c)) { conts.put(s.Contact__c, new Contact(Id = s.Contact__c, Awesome__c = true)); } } } update conts.values(); } global void finish(Database.BatchableContext BC) { } }
Please try the above test class.
Hope this helps you!
I get this error when I run the test class --
Errors: System.QueryException: unexpected token: '('
Stack Trace: Class.BatchAwesomeContact.start: line 5, column 1
Maybe there's something wrong with my query above? I can't configure it.
Use the query like below.Hope this will help.
'SELECT Id, Contact__c, Amount, (SELECT Id, FirstName, LastName, Awesome__c FROM Contacts) FROM Opportunity WHERE Id IN :conts.keySet()';
Will you please change it to batch class?