---
schema_version: "1"
id: 6f0f3652160ea36f8c6f3b709d849221f1e5dc11e9bdd05cf22cf73b24e75858
title: Communicating Across the DOM with Lightning Message Service
collection: developer
version: current
locale: en-us
portal_url: https://docs.salesforce.com/developer/current/en-us/platform/salesforce-pages-developers-guide/guides/pages/message-channel/message-channel-intro.md
canonical_url: https://developer.salesforce.com/docs/platform/salesforce-pages-developers-guide/guide/message-channel-intro.html
source_site: developer.salesforce.com
content_type: documentation
content_hash: 8c536111a4f10fa47d2f3cf9a3a2ae1831dcefec4887c94489c6446a3322b27f
products:
  - Visualforce Developer Guide
  - Platform Developer Content
---

# Communicating Across the DOM with Lightning Message Service

Use Lightning message service to communicate across the DOM within a Lightning page. Communicate between Visualforce pages embedded in the same Lightning page, Aura components, and Lightning web components, including components in a utility bar and pop-out utilities. Choose whether a component subscribes to messages from the entire application, or from only the active area.

If you're switching from Salesforce Classic to Lightning Experience, you can now build Lightning web components that can communicate with existing Visualforce pages or Aura components. You can also use Lightning message service to communicate with softphones via Open CTI.

**important:** Lightning message service is available in Lightning Experience and as a beta feature for Lightning components used in Experience Builder sites.

To access Lightning message service in Visualforce, use the `$MessageChannel` global variable. A message is a serializable JSON object. Examples of data that you can pass in a message include strings, numbers, objects, and booleans. A message can’t contain functions and symbols. The `$MessageChannel` global variable is only available in Lightning Experience.

## Use Message Channels Created Within Your Org

Here's an example of using a Lightning message channel developed within your org.

```visualforce

<apex:page>
    <script>
        // Load the MessageChannel token in a variable
        var SAMPLEMC = "{!$MessageChannel.SampleMessageChannel__c}";
    </script>
</apex:page>

```

Here, we reference a custom message channel with a formula expression `{!$MessageChannel.SampleMessageChannel__c}`. This expression creates a token that we assign to the variable `SAMPLEMC`. This token is unique to your custom message channel and can be used within the Lightning message service API methods. The syntax `SampleMessageChannel__c` refers to a custom instance of the `LightningMessageChannel` metadata type. The `__c` suffix indicates that it’s custom, but note that it isn’t a custom object. See [Create a Message Channel](https://developer.salesforce.com/docs/platform/salesforce-pages-developers-guide/guide/message-channel-publish.md) to learn more.

If your org has a namespace, don’t include it in your message channel expression. For example, if your org’s namespace is MyNamespace, the message channel expression remains `"{!$MessageChannel.SampleMessageChannel__c}"`.

## Use Message Channels Created Outside Your Org

To use message channels from packages created by developers outside of your org, reference them with the syntax `{!$MessageChannel.Namespace_name__c}`. For example, if `SampleMessageChannel` wasn’t local to your org and came from a package with the namespace SamplePackageNamespace, the syntax would be `{$MessageChannel.SamplePackageNamespace__SampleMessageChannel__c}`.

-   **[Create a Message Channel](https://developer.salesforce.com/docs/platform/salesforce-pages-developers-guide/guide/message-channel-create.md)**  


    To create a Lightning Message Channel in your org, use the LightningMessageChannel metadata type.

-   **[Publish on a Message Channel](https://developer.salesforce.com/docs/platform/salesforce-pages-developers-guide/guide/message-channel-publish.md)**  


    To publish on a Message Channel from a Visualforce page, include the `$MessageChannel` global variable in your page's JavaScript code and write a method that calls `sforce.one.publish()`.

-   **[Subscribe and Unsubscribe from a Message Channel](https://developer.salesforce.com/docs/platform/salesforce-pages-developers-guide/guide/message-channel-subscribe.md)**  


    To subscribe and unsubscribe from a message channel, use the `sforce.one.subscribe()` and `sforce.one.unsubscribe()` methods.

-   **[Considerations and Limitations](https://developer.salesforce.com/docs/platform/salesforce-pages-developers-guide/guide/message-channel-considerations.md)**  


    Keep these considerations and limitations in mind when working with Lightning message service in Visualforce.


**See Also**  


-   [Blog: Lightning Message Service](https://developer.salesforce.com/blogs/2019/10/lightning-message-service-developer-preview.html)
-   [Lightning Web Components Developer Guide: Communicating Across the DOM with Lightning Message Service](https://developer.salesforce.com/docs/atlas.en-us.lightning.meta/lightning/message_channel_intro.htm)
-   [Lightning Aura Components Developer Guide: Communicating Across the DOM with Lightning Message Service](https://developer.salesforce.com/docs/atlas.en-us.lightning.meta/lightning/message_channel_intro.htm)
-   [Open CTI Developer Guide: Lightning Message Service Methods for Lightning Experience](https://developer.salesforce.com/docs/atlas.en-us.api_cti.meta/api_cti/sforce_api_cti_methods_lms.htm)

