You need to sign in to do that
Don't have an account?
Mark Maslow 4
VF Page can't find sforce.one.publish method
When attempting to execute this in a VF page:
sforce.one.publish(locationChannel, payload);
I get an error sforce is not defined.
I tried adding this, which got me sforce, but not sforce.one.
<apex:includeScript value="/soap/ajax/48.0/connection.js"/>
<apex:includeScript value="/soap/ajax/48.0/apex.js"/>
Does anyone know how to get the sforce.one.publish method to work in a VF page?
sforce.one.publish(locationChannel, payload);
I get an error sforce is not defined.
I tried adding this, which got me sforce, but not sforce.one.
<apex:includeScript value="/soap/ajax/48.0/connection.js"/>
<apex:includeScript value="/soap/ajax/48.0/apex.js"/>
Does anyone know how to get the sforce.one.publish method to work in a VF page?
I found the below documentation where in they mentioned on the implementation of the method.
>>https://developer.salesforce.com/docs/atlas.en-us.pages.meta/pages/message_channel_publish.htm
Is this the similar way the method is implemented?
Regards,
Anutej
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().
Below is the sample code.
Review below links which gives you more information.
https://developer.salesforce.com/docs/atlas.en-us.pages.meta/pages/message_channel_publish.htm
https://amitsalesforce.blogspot.com/2019/10/lightning-message-service-lms.html
https://www.jitendrazaa.com/blog/salesforce/data-exchange-between-aura-lightning-web-components-lwc-and-visualforce/
Hope above information was helpful.
Please mark as Best Answer so that it can help others in the future.
Thanks,
Vinay Kumar
Did you import both the methods to interact with LMS like below format.
import { publish,subscribe,unsubscribe,createMessageContext,releaseMessageContext } from 'lightning/messageService';
import SAMPLEMC from "@salesforce/messageChannel/MyMessageChannel__c";
Also review working example and try to implement same and that should work.
Thanks,
Vinay Kumar
Uncaught ReferenceError: sforce is not defined
Sample code at:
https://developer.salesforce.com/docs/atlas.en-us.pages.meta/pages/message_channel_publish.htm
<apex:page >
<script> // Load the MessageChannel token in a variable
var SAMPLEMC = "{!$MessageChannel.SampleMessageChannel__c}";
function handleClick() {
const payload = { recordId: "some string", recordData: {value: "some value"}
}
sforce.one.publish(SAMPLEMC, payload); }
</script>
<div>
<p>Publish SampleMessageChannel</p>
<button onclick="handleClick()">Publish</button>
</div>
</apex:page>
Fortunately, I found a workaround here:
https://developer.salesforce.com/blogs/developer-relations/2017/01/lightning-visualforce-communication.html
https://www.codekiat.com/2020/08/Implement-lightning-message-service-lms-salesforce.html