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
RoyalRoyal 

how to know how many batch class are running in the organaization ?

Best Answer chosen by Royal
SeAlVaSeAlVa
Have you tried the following?
List<AsyncApexJob> batchJobs = [
    SELECT ApexClassId 
    FROM AsyncApexJob 
    WHERE 
        JobType = 'BatchApex' AND 
        Status = 'Processing'
];
If this solves your questions, please mark it as "Best Answer" if not, please reply with your doubts.

All Answers

SeAlVaSeAlVa
Have you tried the following?
List<AsyncApexJob> batchJobs = [
    SELECT ApexClassId 
    FROM AsyncApexJob 
    WHERE 
        JobType = 'BatchApex' AND 
        Status = 'Processing'
];
If this solves your questions, please mark it as "Best Answer" if not, please reply with your doubts.

This was selected as the best answer
RoyalRoyal
Hey Thanks SeAIVa,

that is perfect code.

but the thing is salesforce at a time how many Batch class are process (excute) ?

Thanks.
SeAlVaSeAlVa
Hey,

as per the documentation http://www.salesforce.com/us/developer/docs/apexcode/Content/apex_gov_limits.htm
Maximum number of Batch Apex jobs queued or active 5
So you might want to change 
Status = 'Processing'

to 
Status IN ('Processing','Queued')

Kind regards
RoyalRoyal
HI SeAIVa,

i hava couple of doubts please give me answers..
1. is it possible to execute batch class immidiately, without participate in Queue ?
2. is it possible active or deactive Apex class or Trigger at run time(Dynamically through coding) ?
3.how to know how many schedule Apex class are running in org ?
4.how to cover catch block code in Test class ?

it's greate help to me.

Thanks