メタデータ API によるカスタムチャネルの作成とプラットフォームイベントの追加
| 必要なユーザ権限 | |
|---|---|
| メタデータ型のリリースを取得する | 「アプリケーションのカスタマイズ」 |
| メタデータ型を更新する | 「メタデータ API 関数を使用したメタデータの変更」 |
| メタデータ API を使用する | 「API の有効化」 |
この例では、Order_Channel__chn という名前の注文用チャネルを作成し、そのメンバーとして Order_NorthAmer__e と Order_EMEA__e の 2 つのプラットフォームイベントを追加します。
メタデータ API を使用してチャネルおよびチャネルメンバーを作成するには、Visual Studio Code 向け Salesforce 拡張機能や Salesforce CLI などのツールを使用します。詳細は、『メタデータ API 開発者ガイド』の「メタデータ API 開発者ツール」および「クイックスタート: メタデータ API」を参照してください。
次のサンプルは、Order_Channel__chn チャネル用です。ファイル名は Order_Channel__chn.platformEventChannel です。このチャネルがプラットフォームイベントを受け入れるようにするには、channelType に event を指定します。
1<?xml version="1.0" encoding="UTF-8"?>
2<PlatformEventChannel xmlns="http://soap.sforce.com/2006/04/metadata">
3 <channelType>event</channelType>
4 <label>Custom Channel for Orders</label>
5</PlatformEventChannel>このサンプルのチャネルメンバー定義は、カスタムプラットフォームイベントをチャネルに関連付けます。次のチャネルメンバーでは、プラットフォームイベント、Order_NorthAmer__e、およびチャネル Order_Channel__chn を指定します。ファイル名は Order_Channel_chn_Order_NorthAmer_e.platformEventChannelMember です。
1<?xml version="1.0" encoding="UTF-8"?>
2<PlatformEventChannelMember xmlns="http://soap.sforce.com/2006/04/metadata">
3 <eventChannel>Order_Channel__chn</eventChannel>
4 <selectedEntity>Order_NorthAmer__e</selectedEntity>
5</PlatformEventChannelMember>次のチャネルメンバーでは、カスタムプラットフォームイベント、Order_EMEA__e、およびチャネル Order_Channel__chn を指定します。ファイル名は Order_Channel_chn_Order_EMEA_e.platformEventChannelMember です。
1<?xml version="1.0" encoding="UTF-8"?>
2<PlatformEventChannelMember xmlns="http://soap.sforce.com/2006/04/metadata">
3 <eventChannel>Order_Channel__chn</eventChannel>
4 <selectedEntity>Order_EMEA__e</selectedEntity>
5</PlatformEventChannelMember>次の package.xml ファイルは、チャネルと 2 つのチャネルメンバーを参照します。
1<?xml version="1.0" encoding="UTF-8"?>
2<Package xmlns="http://soap.sforce.com/2006/04/metadata">
3 <types>
4 <members>Order_Channel__chn</members>
5 <name>PlatformEventChannel</name>
6 </types>
7 <types>
8 <members>Order_Channel_chn_Order_NorthAmer_e</members>
9 <name>PlatformEventChannelMember</name>
10 </types>
11 <types>
12 <members>Order_Channel_chn_Order_EMEA_e</members>
13 <name>PlatformEventChannelMember</name>
14 </types>
15 <version>59.0</version>
16</Package>