Skip to main content

Add the Order Event and the Filter Expression to a Channel Member

Define the Order Platform Event

Before you can add a channel member, define the platform event that the channel member references.

  1. From Setup, in the Quick Find box, enter Platform Events, and then select Platform Events.
  2. Click New Platform Event.
  3. Provide these values.
    • Label: Order Event
    • Plural Label: Order Events
  1. Select Starts with a vowel sound, if available.
  2. Click Save.
  3. Create three fields. In Custom Fields & Relationships, click New for each field, and follow the wizard.

Field Type

Field Label 

Field Length

Text

Order Number

10

Text

City

50

Number

Amount

16 

Decimal Places: 2

Filter Expression in a Channel Member

To filter your event stream, add a filter expression to a member of a channel, which is represented by PlatformEventChannelMember in Tooling API and Metadata API. The filter expression is for each event entity. The channel member specifies the event entity that is streamed on that channel and also the filter expression that is used to filter the stream of events. A channel can contain multiple members and each member references a distinct event entity. In this project, you add only one channel member for simplicity.

Object diagram that shows the relationship between a PlatformEventChannel and a PlatformEventChannelMember.

The filter expression specifies the event fields and values you want to filter the event stream with. It is based on SOQL and supports a subset of SOQL operators and field types. The filter expression can contain one or more field expressions, joined by a logical operator. In this example, you use this filter expression:

City__c='San Francisco' AND Amount__c<1000

The filtered channel delivers only the event messages that contain the City field value of San Francisco and an Amount field value less than 1,000.

For more information about what the filter expression can contain, see Platform Event Filters in the Platform Events Developer Guide. 

Make a Tooling API Call to Create a Channel Member

  1. In your fork of the Salesforce Platform APIs collection, expand Event Platform > Custom Channels > Platform Event, and click Create channel member.
  2. Click Body and replace the body with this JSON body.
    {
     "FullName": "Order_Filtered_Channel_chn_Order_Event_e",
     "Metadata": {
      "eventChannel": "Order_Filtered_Channel__chn",
      "filterExpression": "City__c='San Francisco' AND Amount__c<1000",
      "selectedEntity": "Order_Event__e"
     }
    }
  3. Click Send.
  4. Verify that the response status is 201 Created.
  5. The response contains the ID of the new custom channel member, which looks something like this.
    {
        "id": "0v88b00000000m1AAA",
        "success": true,
        "errors": [],
        "warnings": [],
        "infos": []
    }
Note

To find out the channels and channel members defined in your org, you can run a SOQL query using Tooling API. For query examples, see PlatformEventChannel and PlatformEventChannelMember in the Tooling API Developer Guide.

Congratulations! You added a filter to a custom channel! Next, you subscribe to the filtered channel and receive a filtered event stream.

Resources

Comparta sus comentarios de Trailhead en la Ayuda de Salesforce.

Nos encantaría saber más sobre su experiencia con Trailhead. Ahora puede acceder al nuevo formulario de comentarios en cualquier momento en el sitio de Ayuda de Salesforce.

Más información Continuar a Compartir comentarios