You need to sign in to do that
Don't have an account?
Dritter
System.UnexpectedException: No more than one executeBatch can be called from within a testmethod
I'm running batch apex to deactivate portal users every night, so we don't limit are limit on licenses. I'm getting this Exception on my test class when pushing the code to production.
System.UnexpectedException: No more than one executeBatch can be called from within a testmethod
I found the following article which seems to have the solution, but I'm not sure where exactly to place the code block:
https://help.salesforce.com/apex/HTViewSolution?id=000176562&language=en_US
Here's the test class:
@isTest
private class KapUserCleanUpSchedulerTest {
public static testmethod void test() {
Test.startTest();
// Schedule the test job
String jobId = System.schedule('testMassScheduledApexonet', KapUserCleanUpScheduler.CRON_EXP, new KapUserCleanUpScheduler());
// Get the information from the CronTrigger API object
CronTrigger ct = [SELECT Id, CronExpression, TimesTriggered, NextFireTime FROM CronTrigger WHERE id = :jobId];
// Verify the expressions are the same
System.assertEquals(KapUserCleanUpScheduler.CRON_EXP, ct.CronExpression);
// Verify the job has not run
System.assertEquals(0, ct.TimesTriggered);
// Verify the next time the job will run
System.assertEquals('2022-09-03 00:00:00', String.valueOf(ct.NextFireTime));
public void finish(Database.BatchableContext);
{
if(!Test.isRunningTest)
Database.executeBatch(new MySecondBatchJob));
}
Test.stopTest();
}
}
I'm new to coding, so any help is appreciated. Thanks!
System.UnexpectedException: No more than one executeBatch can be called from within a testmethod
I found the following article which seems to have the solution, but I'm not sure where exactly to place the code block:
https://help.salesforce.com/apex/HTViewSolution?id=000176562&language=en_US
Here's the test class:
@isTest
private class KapUserCleanUpSchedulerTest {
public static testmethod void test() {
Test.startTest();
// Schedule the test job
String jobId = System.schedule('testMassScheduledApexonet', KapUserCleanUpScheduler.CRON_EXP, new KapUserCleanUpScheduler());
// Get the information from the CronTrigger API object
CronTrigger ct = [SELECT Id, CronExpression, TimesTriggered, NextFireTime FROM CronTrigger WHERE id = :jobId];
// Verify the expressions are the same
System.assertEquals(KapUserCleanUpScheduler.CRON_EXP, ct.CronExpression);
// Verify the job has not run
System.assertEquals(0, ct.TimesTriggered);
// Verify the next time the job will run
System.assertEquals('2022-09-03 00:00:00', String.valueOf(ct.NextFireTime));
public void finish(Database.BatchableContext);
{
if(!Test.isRunningTest)
Database.executeBatch(new MySecondBatchJob));
}
Test.stopTest();
}
}
I'm new to coding, so any help is appreciated. Thanks!
please have a look to this article it really helps you, it will solve your problem.
let me know if it works,
https://help.salesforce.com/apex/HTViewSolution?id=000176562&language=en_US (https://help.salesforce.com/apex/HTViewSolution?id=000176562&language=en_US)