function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
Vishnu_SFDCVishnu_SFDC 

External Entry Point Exception for my batch class

My test class for Batch apex is throwing error when its frocessing more than 1 record. When i set the limit as 1 it works fine. When i increase the limit I get External Entry Point Exception.

<----------Batch Class------------>
global class DEUserCheckOut implements Database.Batchable<sObject>,Database.AllowsCallouts,Database.stateful {
global Database.QueryLocator start(Database.BatchableContext BC) {
String query = 'SELECT Id,Calls_Logged_Today__c,profileId,Check_In__c,Qualification__c,Call_Logged__c From User Where Check_In__c = true Limit 2 ';
return Database.getQueryLocator(query);
}
global void execute(Database.BatchableContext BC, List<User> scope) {
 
for(User e : scope){
{
e.Check_In__C = False;
e.Calls_Logged_Today__c = 0;
Update Scope;
}
}
}
global void finish(Database.BatchableContext BC) { }
}


<-------------Test Class-------------->
@istest(SeeAllData=False)
public class TestDEUserCheckOut{
Static testmethod void TestDEUserCheckOut()
{
Profile p = [SELECT Id FROM Profile WHERE Name='System Administrator'];
        UserRole teleRole = [SELECT Id FROM UserRole WHERE Name='Qualifier' LIMIT 1];
        
         User brian = new User(Alias = 'standt', Email='standarduser@testorg.com',
                EmailEncodingKey='UTF-8', FirstName='Brian', LastName='Mulhair', LanguageLocaleKey='en_US',
                LocaleSidKey='en_US', ProfileId = '00ei0000000iZri', UserRoleId = teleRole.Id,
                TimeZoneSidKey='America/Los_Angeles',IsActive=true,Check_In__c = True, UserName='unique@user.name12345');
            insert brian;
           
   
    Test.startTest();
            
                    
            Database.executeBatch(new DEUserCheckOut(),1);
           
        Test.stopTest();
    
 
}
}


Thanks In Advance.
Best Answer chosen by Vishnu_SFDC
Elie.RodrigueElie.Rodrigue
1 - In your test class, you have an hardcoded profile id, use the one from your query instead
2 - In your batch, get the update scope call out of your loop.
3 - Here's the real full error message you're getting : System.UnexpectedException: No more than one executeBatch can be called from within a testmethod. Please make sure the iterable returned from your start method matches the batch size, resulting in one executeBatch invocation.
Its simply that when testing a batch class, you need to make sure that only one batch will run. You can do that by adding a parameter to your constructor that will tell the maximum number of rows to return and adding it to your batch initilization call.
Or in your start method, you could have something like :


String query = 'SELECT Id,Calls_Logged_Today__c,profileId,Check_In__c,Qualification__c,Call_Logged__c From User Where Check_In__c = true';
if(Test.isRunningTest())
{
query += ' Limit 1';
}
return Database.getQueryLocator(query);

Elie Rodrigue
www.elierodrigue.com