I am trying to create a test class in order to have code coverage for a batch class doing approval processes escalation, but I am receiving the error from the title. I have used the SkipEntryCondition=true at first, but it's not working. (Just FIY: the entry condition is for the Approval_Status__c to be "Ready for Approval" and the quantity > 1, both condition being met). The user & the process definition exist in the Test Environment. I tested separately this as I was suspecting I need to create them manually here.
I've tried to apply the solutions from other threads as this questions has been asked before, but nothing worked in my case. This is my code:
@TestSetup
private static void setup() {
TEST_DataFactory.createBotConfig();
TEST_DataFactory.createDefaultSpecRecords();
TEST_DataFactory.setupCommunityUser();
User user1 = [SELECT Id FROM User WHERE Name = 'MyUsername'];
ProcessDefinition procDef = [SELECT Id FROM ProcessDefinition WHERE Name = 'OrderProcessDefinitionV3'];
Account a = new Account(Name = 'Account Name');
insert a;
Order o = new Order
(
OwnerId = user1.Id,
RecordTypeId = '0123L0000005QqxE',
Type = 'Return Order Ullage',
Name = 'Order name asasd',
AccountId = a.Id,
Case_Quantity__c = 1.0,
EffectiveDate = Date.today(),
Status = 'Draft',
Approval_Status__c = 'Ready for Approval'
);
insert o;
// Create an approval request for the order
Approval.ProcessSubmitRequest req1 = new Approval.ProcessSubmitRequest();
req1.setComments('Submitting request for approval.');
req1.setObjectId(o.Id);
// Submit on behalf of a specific submitter
req1.setSubmitterId(user1.Id);
// Submit the record to specific process and skip the criteria evaluation
req1.setProcessDefinitionNameOrId(procDef.Id);
req1.setSkipEntryCriteria(true);
// Submit the approval request for the order
Approval.ProcessResult result = Approval.process(req1);
}
@IsTest
static void testBehavior() {
BATCH_EscalateOrderApprovalProcess bc = new BATCH_EscalateOrderApprovalProcess();
Database.executeBatch(bc);
}