Newer Version Available
RemoteKeyCalloutEvent
The RemoteKeyCalloutEvent captures events related to the success or failure of a callout that fetches encrypted key material from an end point. Based on the Platform Events framework, a RemoteKeyCalloutEvent is published every time a callout is made to an external key service. This event lets you monitor your cache-only key callouts in real time, and receive alerts about any errors that might occur. You can subscribe to events with after insert Apex triggers and store events in custom objects, security information event management (SIEM), or other back-end systems.
Supported Calls
describeSObjects()
Supported Subscribers
| Subscriber | Supported? |
|---|---|
| Apex Triggers | ![]() |
| Flows | |
| Processes | |
| Pub/Sub API | |
| Streaming API (CometD) | ![]() |
Subscription Channel
/event/RemoteKeyCalloutEvent
Special Access Rules
Access to RemoteKeyCalloutEvent data requires purchasing Salesforce Shield or Shield Platform Encryption. The RemoteKeyCalloutEvent only applies to callouts that fetch cache-only key material.
Event Delivery Allocation Enforced
Yes
Fields
| Field | Details |
|---|---|
| Details |
|
| EventUuid |
|
| ReplayID |
|
| RequestIdentifier |
Available in API version 45.0 and later. |
| StatusCode |
|
| TenantSecretID |
|
Usage
To view a RemoteKeyCalloutEvent and perform custom actions after your callout, create an after insert Apex trigger in Dev Console. These triggers let you assign custom actions for your event. You can set in-app alerts and send email alerts to people who maintain your key service, including users who don’t have a Salesforce login.
For longer-term monitoring, you can store RemoteKeyCalloutEvent data in custom objects and custom fields, SIEM, or other back-end systems. Then use business rules to send alerts. For example, you can set an alert that sends admins an email when something is wrong with a key service.
Here’s an example of an after insert trigger that stores RemoteKeyCalloutEvent results in a custom object called Key Service Callout Log. The custom object also draws data from the TenantSecret object.
| Field Label | Field Name | Data Type |
|---|---|---|
| Key Service Callout Log ID | Name | Auto Number |
| Details | Details__c | Text(255) |
| Replay Detection | Replay_Detection__c | Text (255) |
| Status Code | Status_Code__c | Text(255) |
| Tenant Secret Id | Tenant_Secret_Id__c | Text(50) |
| Tenant Secret Status | Tenant_Secret_Status__c | Text(255) |
| Type | Type__c | Text(100) |
| Version | Version__c | Number(10,0) |
1
2trigger RemoteKeyCalloutEvent on RemoteKeyCalloutEvent (after insert){
3 List<Key_Service_Callout_Log__c> l = new List<Key_Service_Callout_Log__c>();
4 Set<ID> TenantSecretIds = new Set<ID>();
5 Map<ID, TenantSecret> TenantSecrets;
6 for(RemoteKeyCalloutEvent event : Trigger.new){
7 if(event.TenantSecretId != null && !TenantSecretIds.contains(event.TenantSecretId))
8 TenantSecretIds.add(event.TenantSecretId);
9 }
10 if(TenantSecretIds != null && !TenantSecretIds.isEmpty())
11 TenantSecrets = new Map<ID, TenantSecret>([SELECT Type, Version, Status FROM TenantSecret where Id In: TenantSecretIds]);
12
13 for(RemoteKeyCalloutEvent event : Trigger.new){
14 Key_Service_Callout_Log__c log = new Key_Service_Callout_Log__c();
15 log.Status_Code__c = event.StatusCode;
16 log.Tenant_Secret_ID__c = event.TenantSecretId;
17 log.Replay_Detection__c = event.RequestIdentifier;
18 log.Details__c = event.Details;
19 if(TenantSecrets != null && TenantSecrets.containsKey(event.TenantSecretId)){
20 log.Type__c = TenantSecrets.get(event.TenantSecretId).Type;
21 log.Version__c = TenantSecrets.get(event.TenantSecretId).Version;
22 log.Tenant_Secret_Status__c = TenantSecrets.get(event.TenantSecretId).Status;
23 }
24 l.add(log);
25 }
26
27 insert l;
28}1
2@IsTest
3public class without sharing TestRemoteKey { //important: do not enforce sharing
4 @IsTest
5 public static void myUnitMethod1(){
6 List<RemoteKeyCalloutEvent> eList = new List<RemoteKeyCalloutEvent>();
7 List<TenantSecret> tsList = [Select Id, Type, Status From TenantSecret];
8 for(TenantSecret ts : tsList){
9 RemoteKeyCalloutEvent e = new RemoteKeyCalloutEvent();
10 e.TenantSecretId = ts.Id;
11 e.RequestIdentifier = '22222'+ts.Id;
12 e.StatusCode = 'SUCCESS';
13 eList.add(e);
14 }
15 Test.startTest();
16 try {
17 EventBus.publish(eList);
18 Test.getEventBus().deliver();
19 System.debug('delivered... ');
20 } catch(Exception ex) {
21 System.debug(ex.getMessage());
22 Boolean expectedExceptionThrown = ex.getMessage().contains('New Event Cannot be Created') ? true : false;
23 System.AssertEquals(expectedExceptionThrown, true);
24 }To troubleshoot callout errors, review the StatusCode and Details fields. These fields give you information about remote key callout errors or exceptions in raw JSON format. Successful, empty callout, and timeout responses return empty Details fields.
