I'm looking to see if anyone could provide any pointers on the test class I'm trying to write for the following batch class:
public with sharing class TerritoryReassignmentAccounts implements Database.Batchable<SObject> {
// flow calls method and passes to it a list of instances of TerritoryReassignmentVariables class
// Iterates through the list and make a batch call to itself
@InvocableMethod(label = 'Territory Reassignment')
public static void updateAccounts(List<TerritoryReassignmentVariables> IDValues){
for(TerritoryReassignmentVariables itemFromFlow: IDValues) {
Database.executeBatch(new TerritoryReassignmentAccounts(itemFromFlow));
}
}
// State to update records //
TerritoryReassignmentVariables item;
TerritoryReassignmentAccounts(TerritoryReassignmentVariables itemParameter) {
this.item = itemParameter;
}
public Database.QueryLocator start(Database.BatchableContext ctx) {
return Database.getQueryLocator([SELECT Id FROM Account WHERE X2020_New_Territory_Text__c = :item.old2020NTT]);
}
// Queueable Context execution //
public void execute(Database.BatchableContext ctx, Account[] scope) {
for(Account record: scope) {
record.OwnerId = item.newOwnerId;
record.sundog_deprm2__Territory__c = item.newTerritoryID;
record.X2020_New_Territory_Text__c = item.new2020NTT;
}
update scope;
}
public void finish (Database.BatchableContext BC){
Database.executeBatch(new TerritoryReassignInstitutions(item));
}
}
Not sure how useful this will be, but the "updateAccounts" method parameter in the above is coming from this class, whose variable values are being set via a flow:
public with sharing class TerritoryReassignmentVariables {
@InvocableVariable
public String oldOwnerId;
@InvocableVariable
public String newOwnerId;
@InvocableVariable
public String oldTerritoryID;
@InvocableVariable
public String newTerritoryID;
@InvocableVariable
public String old2020NTT;
@InvocableVariable
public String new2020NTT;
@InvocableVariable
public String newVendorAcctID;
@invocableVariable
public String stateAbbreviations;
}
And here's my attempt at the test class. I've tried a lot of different attempts and the error that pops up most often is "Invalid type: TerritoryReassignmentAccounts.updateAccounts". I think the String List I'm creating and then using as the parameter for the test is incorrect but I'm not sure what else to try. Am I missing something obvious?
@isTest
global class AccountUpdateBatchJobTest {
static testMethod void testMethod1() {
String oldOwnerId = '0052h0000018iqH'; //test user2
String newOwnerId = '0052h0000018iq2'; //test user1
String oldTerritoryID = 'a0C2h000001K4MW'; //test user2
String newTerritoryID = 'a0C2h000001K4MR'; //test user1
String old2020NTT = 'AM-Coverage';
String new2020NTT = 'Testing1234';
String newVendorAcctID = '0012h00000McL4E'; //test user1
String stateAbbreviations = 'NC,FL';
List<String> IdValues = new List<String>();
IdValues.add(oldOwnerId);
IdValues.add(newOwnerId);
IdValues.add(oldTerritoryID);
IdValues.add(newTerritoryID);
IdValues.add(old2020NTT);
IdValues.add(new2020NTT);
IdValues.add(newVendorAcctID);
IdValues.add(stateAbbreviations);
List<Account> lstAccount= new List<Account>();
for(Integer i=0 ;i <200;i++) {
Account acc = new Account();
acc.Name ='Name'+i;
acc.X2020_New_Territory_Text__c = 'Testing1234';
lstAccount.add(acc);
}
insert lstAccount;
Test.startTest();
TerritoryReassignmentAccounts obj = new TerritoryReassignmentAccounts.updateAccounts(IdValues);
Database.executeBatch(obj);
Test.stopTest();
}
}