Parallel Subscription Configuration Examples in Tooling API and Metadata API

Configure parallel subscriptions for an Apex trigger by using PlatformEventSubscriberConfig in Tooling API or Metadata API.

Each PlatformEventSubscriberConfig corresponds to one Apex trigger subscriber. To configure parallel subscriptions, use these fields in PlatformEventSubscriberConfig: NumPartitions and PartitionKey.

  • The NumPartitions field is the number of parallel subscriptions, or partitions, that are created internally for an Apex trigger. It can be a number from 1 through 10.
  • The PartitionKey field value is hashed. Based on the generated hash value, the system determines which partition to send the event to. PartitionKey can be the standard EventUuid field or a required custom field of the platform event that the Apex trigger subscribes to. For the standard EventUuid field, the partition key format is the field name without the event name: EventUuid. For a custom field, the partition key includes the event name as a prefix in this format: EventName__e.FieldName__c.

Example: Tooling API Request for the EventUuid Partition Key Field

This example shows the body of a REST request for PlatformEventSubscriberConfig in Tooling API. It specifies the EventUuid partition key and three partitions. PlatformEventConsumerId references the ID of the Apex trigger.

{
    "DeveloperName":"MyOrderEventTriggerConfig",
    "MasterLabel":"MyOrderEventTriggerConfig",
    "PlatformEventConsumerId": "Apex_Trigger_Id",
    "PartitionKey": "EventUuid",
    "NumPartitions": "3"
}

Example: Tooling API Request for a Custom Partition Key Field

This example shows the body of a REST request for PlatformEventSubscriberConfig in Tooling API. It specifies the name of a custom event field in PartitionKey and three partitions. PlatformEventConsumerId references the ID of the Apex trigger.

{
    "DeveloperName":"MyOrderEventTriggerConfig",
    "MasterLabel":"MyOrderEventTriggerConfig",
    "PlatformEventConsumerId": "Apex_Trigger_Id",
    "PartitionKey": "Order_Event__e.Order_Number__c",
    "NumPartitions": "3"
}

Example: Metadata API for the EventUuid Partition Key Field

This example shows the definition of PlatformEventSubscriberConfig in Metadata API for the EventUuid standard field specified in partitionKey and three partitions specified in numPartitions. The platformEventConsumer field is the name of the Apex trigger.

<?xml version="1.0" encoding="UTF-8"?>
<PlatformEventSubscriberConfig xmlns="http://soap.sforce.com/2006/04/metadata">
    <masterLabel>MyOrderEventTriggerConfig</masterLabel>
    <platformEventConsumer>MyOrderEventTrigger</platformEventConsumer>
    <numPartitions>3</numPartitions>
    <partitionKey>EventUuid</partitionKey>
</PlatformEventSubscriberConfig>

This package.xml manifest file references the PlatformEventSubscriberConfig component.

<?xml version="1.0" encoding="UTF-8"?>
<Package xmlns="http://soap.sforce.com/2006/04/metadata">
    <types>
        <name>PlatformEventSubscriberConfig</name>
        <members>MyOrderEventTriggerConfig</members>
    </types>
    <version>62.0</version>
</Package>

Example: Metadata API for a Custom Partition Key Field

This example shows the definition of PlatformEventSubscriberConfig in Metadata API for the Order_Number__c custom field that is specified in partitionKey and three partitions specified in numPartitions. The platformEventConsumer field is the name of the Apex trigger.

<?xml version="1.0" encoding="UTF-8"?>
<PlatformEventSubscriberConfig xmlns="http://soap.sforce.com/2006/04/metadata">
    <masterLabel>MyOrderEventTriggerConfig</masterLabel>
    <platformEventConsumer>MyOrderEventTrigger</platformEventConsumer>
    <numPartitions>3</numPartitions>
    <partitionKey>Order_Event__e.Order_Number__c</partitionKey>
</PlatformEventSubscriberConfig>

This package.xml manifest file references the PlatformEventSubscriberConfig component.

<?xml version="1.0" encoding="UTF-8"?>
<Package xmlns="http://soap.sforce.com/2006/04/metadata">
    <types>
        <name>PlatformEventSubscriberConfig</name>
        <members>MyOrderEventTriggerConfig</members>
    </types>
    <version>62.0</version>
</Package>