I am having trouble finding this information.

I am finding lots of stuff on communicating between a lightning component and Visualforce page when the Visualforce page is embedded inside the lightning component as an iframe, which involves doing postMessages and what not.

However, my situation is that I have a Visualforce page that I put a lightning component on.

I want the user to fill out the form in the lightning component, then click 'OK', and be able to get that info back on the Visualforce page. However, I am unsure how you perform this kind of communication. The Lightning component is not in an iframe when you embed it in a Visualforce page, so doing some complicated postMessage should not be necessary.

  • 1
    You should be able to pass in a callback as an attribute when you instantiate the lightning component. I've done it before, but am not sure if Salesforce blocks this now... give me a few mins and I may get time to provide an example. Sep 6 '18 at 18:00
  • Sure, I'd like to see an example of this. Do I just set it up like: $Lightning.createComponent('c:myComponent',{'callback': someFunctionOnVFPage}, function(cmp){}); ? Hmm... I am unsure how you then trigger that from the Lightning component? Sep 6 '18 at 18:03

To communicate from the component to the VisualForce page, use a callback function. For example:

 var someFunctionOnVFPage = function(param){

 {'callback':   someFunctionOnVFPage}, 

In the component:

component.get('v.callback')('hey vf page!!');
  • Very nice, what do you put the callback to as far as attribute type goes? Sep 6 '18 at 18:16
  • Just make it an object... due to Javascript's type system, it can be anything, really. Sep 6 '18 at 18:19

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.