+ Start a Discussion
krish4ukrish4u 

How to get Apex class name based on batch job id in batch apex

Hi Folks,

 

How to get the Apex class name of the batch job id in batch apex. can any one suggest me. this is very urgent..............pleaseeeee......................

 

thanks

krish

Best Answer chosen by Admin (Salesforce Developers) 
SLockardSLockard

The objects are related like this:

 

AsyncapexJob aJ = [SELECT Id, ApexClassID FROM AsyncapexJob WHERE Id = 'batchJobIdHere'];
system.debug(aJ);
ApexClass aC = [SELECT Id, Name FROM ApexClass WHERE Id =: aJ.ApexClassID];
system.debug(aC);

 Hope that helps!

All Answers

SLockardSLockard

The objects are related like this:

 

AsyncapexJob aJ = [SELECT Id, ApexClassID FROM AsyncapexJob WHERE Id = 'batchJobIdHere'];
system.debug(aJ);
ApexClass aC = [SELECT Id, Name FROM ApexClass WHERE Id =: aJ.ApexClassID];
system.debug(aC);

 Hope that helps!

This was selected as the best answer
Jesus RamirezJesus Ramirez

Recently I've done with this query: 

SELECT ApexClassId, CompletedDate, CreatedById, CreatedDate, ExtendedStatus, Id, JobItemsProcessed, JobType, LastProcessed, LastProcessedOffset, MethodName, NumberOfErrors, ParentJobId, Status, TotalJobItems from AsyncApexJob where ApexClassId IN (Select Id from ApexClass where Name = 'ClassName1', 'ClassName2', 'Etc')
Cheers!