I want to use LMS to publish data from the VF page and receive it in Aura Component.

I have an Aura Component and am trying to iframe a Visualforce page in it.

<iframe src='/apex/VFLMS'/>

And am trying to publish the data to the Lightning Message channel from VFPage and subscribe to it in Aura Component.

When I see the output I get sforce is not defined.

I don't get the error when I try to use Visualforce standard component and drop the VF page into the standard component in the Lightning App Builder.

I have also made the VFPage be lightning available.

Here is my VF page

<apex:page lightningStylesheets="true">

    <!-- tried including api.js and it gives this error → Uncaught ReferenceError: Sfdc is not defined-->
    <button onclick="publishLeadData()"> Publish Msg</button>

        var LEAD_DATA_CHANNEL = "{!$MessageChannel.LeadDataMessageChannel__c}";

        function publishLeadData() {

            const message = {
                recordId: '001XXXXXXXXXXX',
                name: "Testing"
            sforce.one.publish(LEAD_DATA_CHANNEL, message);


This is the Aura Component

<aura:component implements="flexipage:availableForRecordHome,force:hasRecordId" access="global" >
    <aura:attribute name="recordValue" type="String" />
                              onMessage="{! c.handleLeadDataMessage }"
    <iframe src="/apex/LMSVF" frameborder="0" />
    {! v.recordValue }

And this is the controller.js file

    handleLeadDataMessage : function(component, event, helper) {
        if (event != null && event.getParams() != null) {
            let params = event.getParams();
            component.set("v.recordValue", JSON.stringify(params, null, "\t"));
  • I don't have an answer but thought I'd simplify the question for other who come here. I think what you're really trying to ask is: "I have an Aura component that uses an iFrame to include a Visualforce page. That Visualforce page does not have access to the sforce.one object. Is there a way to give that VF page access to the sforce.one object so that it can publish to LMS? I do not want to use the undocumented isdtp=p1 query parameter. Alternatively, if there is no way for the VF page to access the sforce.one object, is there any other way to publish to LMS from a VF page?" Commented Aug 31, 2020 at 20:44
  • Exactly @JoeFlowers Thanks for summarising it. Commented Sep 1, 2020 at 4:36

2 Answers 2


As per the docs, "Lightning Message Service does not work in Visualforce pages that are included in Lightning Experience via iframes, including <wave:dashboard>, <apex:iframe>, and the standard HTML <iframe> tag.

The intent of LMS isn't to serve as a shortcut for a VF page embedded in an iFrame to send a message to its immediate container. Rather, it's purpose is for solving the harder problem of cross-DOM-cross-ui-technology messaging.


As mentioned in the above post we can't use LMS in this situation, a workaround for this would be using <HTMLREFERENCETOIFRAME>.contentwindow.postMessage(). Please refer to these posts - https://sfwiseguys.wordpress.com/2020/08/10/lwc-with-vf-in-an-iframe-bidirectional-communication/#:~:text=LWC%20to%20VF%20%E2%80%93,pass%20to%20the%20other%20window.,


  • 1
    Can you add some relevant content from those links? Links on their own tend to break over time
    – Matt Lacey
    Commented May 5, 2021 at 2:12
  • re-iterating on the previous request Commented Jan 29 at 16:11

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .