You need to sign in to do that
Don't have an account?
Alex Meza
Writing a test class for a batch class trouble-shooting.
I have an apex batch class that I was able to get workig in my sandbox enviorment and that is ready for deployment into my production enviroment.
However when I went to write the test class for this I ran into some trouble, with an error message that says line 50 = Test Class Error: Argument must be an object that implements Database.Batchable.
Can you guys help me get over this hurdle or tell me if i need a new test class code in order to be able to deploy to production? Below are my batch class and my test class thanks.
Batch Class
However when I went to write the test class for this I ran into some trouble, with an error message that says line 50 = Test Class Error: Argument must be an object that implements Database.Batchable.
Can you guys help me get over this hurdle or tell me if i need a new test class code in order to be able to deploy to production? Below are my batch class and my test class thanks.
Batch Class
global class UpdateContactsVoter implements Database.Batchable<sObject>{ global Database.QueryLocator start(Database.BatchableContext BC){ String query = 'Select ID,FirstName,LastName,MailingPostalCode from contact where contact.voter_file_id__c = null'; return Database.getQueryLocator(query); } global void execute(Database.BatchableContext info, List<contact> scope){ Set<String> set_Str = new Set<string>(); Map<String,Voter_File_TX__c> mp_VoterFile; for(Voter_File_TX__c VoterFile : [Select ID,First_Name__c, Last_Name__c,Zipcode__c, Contact__c From Voter_File_TX__c] ){ if(mp_VoterFile==null){ mp_VoterFile = new Map<String,Voter_File_TX__c>(); } mp_VoterFile.put(VoterFile.First_Name__c +''+VoterFile.Last_Name__c +''+VoterFile.Zipcode__c,VoterFile); } for(Contact ContactList : scope){ if(mp_VoterFile!=null && mp_VoterFile.containsKey(ContactList.FirstName+''+ ContactList.LastName+''+ ContactList.MailingPostalCode)) { mp_VoterFile.get(ContactList.FirstName +''+ ContactList.LastName +''+ ContactList.MailingPostalCode).Contact__c = ContactList.id; } } if(mp_VoterFile!=null && mp_VoterFile.values()!=null){ update mp_VoterFile.values(); } } global void finish(Database.BatchableContext info){ } }
Test Class
line 50 = Test Class Error: Argument must be an object that implements Database.Batchable.
@isTest public class TestClassUpdateContacts { static testMethod void testMethod1() { List<Contact> lstContact= new List<Contact>(); List<Voter_File_TX__c> lstVoterfile = new List<Voter_File_TX__c>(); if(contact.voter_file_id__c == null && voter_file_tx__c.contact__c == null) { Contact cont = new Contact(); cont.FirstName ='Test'; cont.LastName = 'Test'; cont.id = 'Test'; cont.MailingPostalCode = 'test'; insert cont; Voter_File_TX__c vf = new Voter_File_TX__c(); vf.First_Name__c ='Test'; vf.Last_Name__c ='Test'; vf.RNC_ID__c = 'Test'; vf.Zipcode__c = 'Test'; vf.First_Name__c = cont.FirstName ; vf.Last_Name__c = cont.LastName ; vf.Zipcode__c = cont.MailingPostalCode ; vf.Contact__c = cont.Id ; insert vf; cont.FirstName = vf.First_Name__c ; cont.LastName = vf.Last_Name__c ; cont.MailingPostalCode = vf.Zipcode__c; cont.RNC_ID__c = vf.RNC_ID__c ; update cont; } else { contact cont1 = new Contact(); Voter_File_TX__c vf1 = new Voter_File_TX__c(); cont1.Voter_File_ID__c = null; vf1.Contact__c = null; } insert lstContact; update lstContact; Test.startTest(); TestClassUpdateContacts obj = new TestClassUpdateContacts(); DataBase.executeBatch(obj); Test.stopTest(); } }
UpdateContactsVoter obj = new UpdateContactsVoter();
Thanks
All Answers
At line 49/50 you are trying to execute your test class like a batch . You can'nt execute any test class like a batch class. You need to call your batch class in place of those lines.
UpdateContactsVoter obj = new UpdateContactsVoter();
Thanks