I have the following problem in a test class.
Constructor not defined: [Soma_Dependentes_Update].<Constructor>()
Test class of the batch process:
@isTest
public class Soma_Dependentes_UpdateTest {
@isTest
public static void testeit() {
Account acc = new Account(Name='Dependentes');
insert acc;
Test.startTest();
Soma_Dependentes_Update batch = new Soma_Dependentes_Update();
Id batchId = Database.executeBatch(batch);
Test.stopTest();
}
}
Here's the Batch class:
global class Soma_Dependentes_Update implements Database.Batchable<sObject> {
global final String Query;
global final String Field;
global final Integer Value;
global Soma_Dependentes_Update(String q, String f, Integer v) {
Query = q; Field = f; Value = v;
}
global Database.QueryLocator start(Database.BatchableContext BC) {
return Database.getQueryLocator(query);
}
global void execute(Database.BatchableContext BC, List<Account> scope) {
for(Account acc : scope) {
acc.put(Field, Value);
}
update scope;
}
global void finish(Database.BatchableContext BC) {
}
}
I use the following snippet parameters in Execute Anonymous window:
//Parametriza e executa a classe Soma_Dependentes_Update.
String q = 'SELECT SomaDependentes__c FROM Account WHERE Name LIKE \'%Dependentes%\'';
String f = 'SomaDependentes__c';
public list<AggregateResult> countDep = new list<AggregateResult>();
countDep = [SELECT sum(Dependentes__c)am FROM Contact WHERE Account.Name LIKE '%Dependentes%'];
String str = String.valueOf(countDep[0].get('am'));
Integer v = Integer.valueOf(str);
//Executa o Job para atualizaçAo de SomaDependentes__c no objeto Conta.
ID jobID = Database.ExecuteBatch(new Soma_Dependentes_Update(q, f, v));
Can anyone help to identify what I'm doing wrong with the code?