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
J&A-DevJ&A-Dev 

Is it possible to have multiple Batch Apex classes on the same object?

Hi,

 

I have 2 Batch Apex classes that update contact records. Now, I'm trying to write the test method for both, and it seems that when I attempt to simulate the batch job for either job, the other batch job runs as well and I get a runtime error. If I comment out one of the jobs, then other job runs fine and I get 100% coverage (on that particular batch apex job).

 

Is there anything in particular that I need to do to be able to test multiple Apex jobs?

 

Thanks in advance.

Anand@SAASAnand@SAAS
If you have two apex batch jobs for the same Object, how are they triggered? Some code of your batches would be useful to help point you in a direction. If there's a trigger that is starting your batch you might want to put some logic in the trigger(or apex class) to determine if the batch needs to be started.
J&A-DevJ&A-Dev

Hi,

 

Both Batch Apex jobs are triggered by the scheduler. Originally, I was creating a constructor (for my Batch Apex class) and passing the query as parameter within the constructor. When I did this, I was getting a runtime error on my test class. I decided to get rid of the constructor w/ the parameter, and now all it's good.

 

I need to understand why it didn't work w/ the constructors, but I think I'll do that once I have some free time :-) Thanks for checking into this though.