How to send data from Embedded lightning component back to Visualforce page?

The name of the pictureThe name of the pictureThe name of the pictureClash Royale CLAN TAG#URR8PPP





.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty margin-bottom:0;







up vote
2
down vote

favorite












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.







share|improve this question
















  • 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.
    – Caspar Harmer
    Sep 6 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?
    – Tyler Dahle
    Sep 6 at 18:03
















up vote
2
down vote

favorite












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.







share|improve this question
















  • 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.
    – Caspar Harmer
    Sep 6 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?
    – Tyler Dahle
    Sep 6 at 18:03












up vote
2
down vote

favorite









up vote
2
down vote

favorite











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.







share|improve this question












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.









share|improve this question











share|improve this question




share|improve this question










asked Sep 6 at 17:55









Tyler Dahle

40419




40419







  • 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.
    – Caspar Harmer
    Sep 6 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?
    – Tyler Dahle
    Sep 6 at 18:03












  • 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.
    – Caspar Harmer
    Sep 6 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?
    – Tyler Dahle
    Sep 6 at 18:03







1




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.
– Caspar Harmer
Sep 6 at 18:00




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.
– Caspar Harmer
Sep 6 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?
– Tyler Dahle
Sep 6 at 18:03




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?
– Tyler Dahle
Sep 6 at 18:03










1 Answer
1






active

oldest

votes

















up vote
5
down vote



accepted










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



 <script>
var someFunctionOnVFPage = function(param)
alert(param);


$Lightning.createComponent('c:myComponent',
'callback': someFunctionOnVFPage,
function(cmp));


In the component:



component.get('v.callback')('hey vf page!!');





share|improve this answer




















  • Very nice, what do you put the callback to as far as attribute type goes?
    – Tyler Dahle
    Sep 6 at 18:16










  • Just make it an object... due to Javascript's type system, it can be anything, really.
    – Caspar Harmer
    Sep 6 at 18:19










  • Sweet, that works great! Thank you.
    – Tyler Dahle
    Sep 6 at 20:31










Your Answer







StackExchange.ready(function()
var channelOptions =
tags: "".split(" "),
id: "459"
;
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function()
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled)
StackExchange.using("snippets", function()
createEditor();
);

else
createEditor();

);

function createEditor()
StackExchange.prepareEditor(
heartbeatType: 'answer',
convertImagesToLinks: false,
noModals: false,
showLowRepImageUploadWarning: true,
reputationToPostImages: null,
bindNavPrevention: true,
postfix: "",
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
);



);













 

draft saved


draft discarded


















StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fsalesforce.stackexchange.com%2fquestions%2f231513%2fhow-to-send-data-from-embedded-lightning-component-back-to-visualforce-page%23new-answer', 'question_page');

);

Post as a guest






























1 Answer
1






active

oldest

votes








1 Answer
1






active

oldest

votes









active

oldest

votes






active

oldest

votes








up vote
5
down vote



accepted










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



 <script>
var someFunctionOnVFPage = function(param)
alert(param);


$Lightning.createComponent('c:myComponent',
'callback': someFunctionOnVFPage,
function(cmp));


In the component:



component.get('v.callback')('hey vf page!!');





share|improve this answer




















  • Very nice, what do you put the callback to as far as attribute type goes?
    – Tyler Dahle
    Sep 6 at 18:16










  • Just make it an object... due to Javascript's type system, it can be anything, really.
    – Caspar Harmer
    Sep 6 at 18:19










  • Sweet, that works great! Thank you.
    – Tyler Dahle
    Sep 6 at 20:31














up vote
5
down vote



accepted










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



 <script>
var someFunctionOnVFPage = function(param)
alert(param);


$Lightning.createComponent('c:myComponent',
'callback': someFunctionOnVFPage,
function(cmp));


In the component:



component.get('v.callback')('hey vf page!!');





share|improve this answer




















  • Very nice, what do you put the callback to as far as attribute type goes?
    – Tyler Dahle
    Sep 6 at 18:16










  • Just make it an object... due to Javascript's type system, it can be anything, really.
    – Caspar Harmer
    Sep 6 at 18:19










  • Sweet, that works great! Thank you.
    – Tyler Dahle
    Sep 6 at 20:31












up vote
5
down vote



accepted







up vote
5
down vote



accepted






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



 <script>
var someFunctionOnVFPage = function(param)
alert(param);


$Lightning.createComponent('c:myComponent',
'callback': someFunctionOnVFPage,
function(cmp));


In the component:



component.get('v.callback')('hey vf page!!');





share|improve this answer












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



 <script>
var someFunctionOnVFPage = function(param)
alert(param);


$Lightning.createComponent('c:myComponent',
'callback': someFunctionOnVFPage,
function(cmp));


In the component:



component.get('v.callback')('hey vf page!!');






share|improve this answer












share|improve this answer



share|improve this answer










answered Sep 6 at 18:08









Caspar Harmer

12.1k21748




12.1k21748











  • Very nice, what do you put the callback to as far as attribute type goes?
    – Tyler Dahle
    Sep 6 at 18:16










  • Just make it an object... due to Javascript's type system, it can be anything, really.
    – Caspar Harmer
    Sep 6 at 18:19










  • Sweet, that works great! Thank you.
    – Tyler Dahle
    Sep 6 at 20:31
















  • Very nice, what do you put the callback to as far as attribute type goes?
    – Tyler Dahle
    Sep 6 at 18:16










  • Just make it an object... due to Javascript's type system, it can be anything, really.
    – Caspar Harmer
    Sep 6 at 18:19










  • Sweet, that works great! Thank you.
    – Tyler Dahle
    Sep 6 at 20:31















Very nice, what do you put the callback to as far as attribute type goes?
– Tyler Dahle
Sep 6 at 18:16




Very nice, what do you put the callback to as far as attribute type goes?
– Tyler Dahle
Sep 6 at 18:16












Just make it an object... due to Javascript's type system, it can be anything, really.
– Caspar Harmer
Sep 6 at 18:19




Just make it an object... due to Javascript's type system, it can be anything, really.
– Caspar Harmer
Sep 6 at 18:19












Sweet, that works great! Thank you.
– Tyler Dahle
Sep 6 at 20:31




Sweet, that works great! Thank you.
– Tyler Dahle
Sep 6 at 20:31

















 

draft saved


draft discarded















































 


draft saved


draft discarded














StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fsalesforce.stackexchange.com%2fquestions%2f231513%2fhow-to-send-data-from-embedded-lightning-component-back-to-visualforce-page%23new-answer', 'question_page');

);

Post as a guest













































































Comments

Popular posts from this blog

What does second last employer means? [closed]

Installing NextGIS Connect into QGIS 3?

One-line joke