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
Giancarlo AmatiGiancarlo Amati 

Email alerts for Apex Batch jobs - how to?

Hi Team,

I'm reviewing an Apex Batch job that failed overnight. I would like to update the email address that it sends in case of failure. I cannot figure out where this is built, but I've found this code in the Apex Class. There is a function called 'Label.BatchJobMonitors.split(';')' but I cannot find the definition. The 'toAddresses' is build based on that.
Any help?
Thank you
String status = (String.isEmpty(job.Status)) ? '' : job.Status;
          status = status.toLowerCase();
          ApexClass ac = [SELECT Id, Name FROM ApexClass WHERE Id =: job.ApexClassID];
      String className = ac.Name;
          Messaging.SingleEmailMessage mail = new Messaging.SingleEmailMessage();
          String[] toAddresses = Label.BatchJobMonitors.split(';');
          mail.setToAddresses(toAddresses);
          mail.setSubject(subject);

 
Best Answer chosen by Giancarlo Amati
Hemant_SoniHemant_Soni
Hi Giancarlo,
This is very simple there is custom label "BatchJobMonitors" which you can look like this (Setup > Quick Find > Custom label). In this label some emails id are added with semicolon for example : 'abc@test.com;xyz@abc.com'. and when this label split on ';' semicolon then it will automatically converted into string array.

Please let me know if need more information.

Thanks
Hemant

All Answers

Hemant_SoniHemant_Soni
Hi Giancarlo,
This is very simple there is custom label "BatchJobMonitors" which you can look like this (Setup > Quick Find > Custom label). In this label some emails id are added with semicolon for example : 'abc@test.com;xyz@abc.com'. and when this label split on ';' semicolon then it will automatically converted into string array.

Please let me know if need more information.

Thanks
Hemant
This was selected as the best answer
Giancarlo AmatiGiancarlo Amati
WOW!!!!! I love my job! This is mindblowing!
Thank you.
GC