この文章は Salesforce 機械翻訳システムを使用して翻訳されました。詳細はこちらをご参照ください。
英語に切り替える

メタデータ API によるカスタムチャネルの作成とプラットフォームイベントの追加

メタデータ API を使用することで、チャネルとチャネルメンバーを作成できます。アプリケーションライフサイクル管理プロセスのアプリケーション開発、テスト、リリース、本番リリースなどでは、メタデータ API を利用することをお勧めします。チャネルの設定のみを行う場合は、REST によって Tooling 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 です。このチャネルがプラットフォームイベントを受け入れるようにするには、channelTypeevent を指定します。

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>58.0</version>
16</Package>