Apex · Salesforce

How to find number apex batch class in my org?

Please run below script in developer console anonymous or workbench anonymous window. You will receive email with csv file attachment.

list<ApexClass> lstApex = [SELECT Id, NamespacePrefix, Name, ApiVersion, Status, IsValid, BodyCrc, Body, LengthWithoutComments FROM ApexClass where NamespacePrefix = null];
string excelHeader = ‘ApexName\n’;
for(ApexClass iterator : lstApex) {
if(iterator.Body.contains(‘Database.Batchable’)) {
system.debug(iterator.Name);
excelHeader += iterator.Name +’\n’;
}
}
Messaging.EmailFileAttachment csvAttc = new Messaging.EmailFileAttachment();
blob csvBlob = Blob.valueOf(excelHeader);
string csvname= ‘ApexClassBatchName.csv’;
csvAttc.setFileName(csvname);
csvAttc.setBody(csvBlob);
Messaging.SingleEmailMessage email =new Messaging.SingleEmailMessage();
String[] toAddresses = new list<string> {‘Enter your email address’};
String subject =’Apex Batch Class Name CSV’;
email.setSubject(subject);
email.setToAddresses( toAddresses );
email.setPlainTextBody(‘Apex Batch Class Name CSV ‘);
email.setFileAttachments(new Messaging.EmailFileAttachment[]{csvAttc});
Messaging.SendEmailResult [] r = Messaging.sendEmail(new Messaging.SingleEmailMessage[] {email});

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s