Open VS Code > Extensions > Salesforce Extension Pack (Installed via VS Code Extensions tab: Ctrl+Shift+X or Cmd+Shift+X)
Important Note on Deployment: This Apex Trigger must be created and deployed using VS Code / Salesforce CLI. Salesforce does not support creating Apex Triggers with the after insert event on SearchIndexJobStatusEvent directly within the Developer Console UI. This Platform event is currently not subscribable within Platform Event Trigger Flow.
trigger SearchIndexJobStatusTrigger on SearchIndexJobStatusEvent (after insert) {
List<Messaging.SingleEmailMessage> emails = new List<Messaging.SingleEmailMessage>();
for (SearchIndexJobStatusEvent evt : Trigger.new) {
if (evt.RuntimeStatus == 'FAILED') {
Messaging.SingleEmailMessage mail = new Messaging.SingleEmailMessage();
// Set recipients - update with your admin email(s)
mail.setToAddresses(new List<String>{ '<set_your_admin_email>' });
// Set your Email Subject Line
mail.setSubject('⚠️ Search Index FAILED: ' + evt.ApiName);
// Create your email Body message
String body = 'A Data Cloud Search Index job has FAILED.\n\n'
+ 'Index API Name: ' + evt.ApiName + '\n'
+ 'Status: ' + evt.RuntimeStatus + '\n'
+ 'Error Code: ' + evt.ErrorCode + '\n'
+ 'Event Created: ' + evt.EventCreationDate + '\n'
+ 'Index Refreshed On: ' + evt.IndexRefreshedOn + '\n\n'
+ 'Please investigate the Search Index in Data Cloud.';
mail.setPlainTextBody(body);
mail.setSaveAsActivity(false);
emails.add(mail);
}
}
// Check if the emails object has mail - If not empty, send immediately
if (!emails.isEmpty()) {
Messaging.sendEmail(emails);
}
}
SearchIndexJobStatusEvent fields:
Fields |
Data Type |
Description |
| ApiName | string | The search index API name. |
| ErrorCode | string | Reference code for the type of error that occurred. |
| EventCreationDate | datetime | The date and time when the event occurred. |
| EventPublishDate | datetime | The date and time when the event was published. |
| EventType | string | The type of event that occurred. |
| EventUuid | string | A universally unique identifier (UUID) that identifies a platform event message. |
| IndexRefreshedOn | datetime | The date and time of the last refresh on the index. |
| ReplayId | string | Represents an ID value that is populated by the system and refers to the position of the event in the event stream. Replay ID values aren’t guaranteed to be contiguous for consecutive events. A subscriber can store a replay ID value and use it on resubscription to retrieve missed events that are within the retention window. |
| RuntimeStatus | string | The last run status of the search index such as Ready, In Progress, or Failed. |
| SchemaVersion | string | The version of the event schema. |
<?xml version="1.0" encoding="UTF-8"?>
<PlatformEventSubscriberConfig xmlns="http://soap.sforce.com/2006/04/metadata">
<platformEventConsumer>SearchIndexJobStatusTrigger</platformEventConsumer>
<!-- Name of the apex trigger -->
<batchSize>500</batchSize>
<masterLabel>SearchIndexJobStatusTriggerConfig</masterLabel>
<user>dc_tommy.mac@salesforce.com</user>
<!-- username of the user running this trigger. If the user is deactivated, it could cause silent issue. Be sure to create a dedicated admin user to run this trigger. -->
<isProtected>false</isProtected>
</PlatformEventSubscriberConfig>
005390905

We use three kinds of cookies on our websites: required, functional, and advertising. You can choose whether functional and advertising cookies apply. Click on the different cookie categories to find out more about each category and to change the default settings.
Privacy Statement
Required cookies are necessary for basic website functionality. Some examples include: session cookies needed to transmit the website, authentication cookies, and security cookies.
Functional cookies enhance functions, performance, and services on the website. Some examples include: cookies used to analyze site traffic, cookies used for market research, and cookies used to display advertising that is not directed to a particular individual.
Advertising cookies track activity across websites in order to understand a viewer’s interests, and direct them specific marketing. Some examples include: cookies used for remarketing, or interest-based advertising.