How to create a MessageChannel in Salesforce using VS Code?

How to create a MessageChannel in Salesforce using VS Code?

To create a MessageChannel, use the below steps

1. Open VS Code.

2. Create a Folder with the name “messageChannels” under force-app\main\default.

3. Create a file with Channel name followed by suffix “.messageChannel-meta.xml”.

4. Add the below content(Change the variable names and add/remove as needed).

Sample Code:

<?xml version="1.0" encoding="UTF-8"?>
<LightningMessageChannel xmlns="http://soap.sforce.com/2006/04/metadata">
    <masterLabel>SampleChannel</masterLabel>
    <isExposed>true</isExposed>
    <description>This is a sample Lightning Message Channel.</description>
    <lightningMessageFields>
        <fieldName>variable1</fieldName>
        <description>Variable 1</description>
    </lightningMessageFields>
    <lightningMessageFields>
        <fieldName>variable2</fieldName>
        <description>Variable 2</description>
    </lightningMessageFields>
</LightningMessageChannel>

5. Add the below in your package.xml.

    <types>
        <members>*</members>
        <name>LightningMessageChannel</name>
    </types>

6. Deploy the MessageChannel to the Source Org by selecting SFDX: Deploy this Source to Org.

Using the above steps, LightningMessageChannel can be created in the Salesforce org using VS Code.

Leave a Reply