+ Start a Discussion
veeru_pariveeru_pari 

Getting class name dynamically

Hi ,

here is the code snippet which has my ques

 

String variable= 'Batch_CaseEmail'(class name);//Here the value in the string is class name.I want to get the class names like that dynamically after the batch is run from (Monitorin--ApexJobs--ApexClass('Batch_CaseEmail')).There are many batch classes those we need to get dynamicalli and store in variable and this variable is provided as value in Name field marked in below SOQL query
    global Integer getBatchesCount() {
    List<AsyncApexJob> lstjobs=[
    SELECT
        Id,
        TotalJobItems
    FROM
        AsyncApexJob
    WHERE CompletedDate = LAST_N_DAYS:365 AND JobType='BatchApex' AND ApexClassId IN (SELECT Id FROM ApexClass WHERE NamespacePrefix =null  AND Name =:variable)];

Integer jobItemsCount = 0;
Integer batchesCount = 0;
for(AsyncApexJob async : lstjobs) {
    jobItemsCount +=async.TotalJobItems;
    batchesCount++;
   
    }

   return batchesCount;
    }

 

}

 

So ho can i achieve this .Please help me on this

 

Thanks,

Veeraiah