I created a lightning component that will house a drag and drop file uploader and handle all of its goings ons.

Then I bring it into my Visualforce page like so:

$Lightning.use('c:DropZoneComponentApp', function(){    
    $Lightning.createComponent('c:DropZoneComponent', {eventId: currentEvent.taskId}, 'eventDropzone', function(cmp){
        console.log('Component Created!', cmp);
        //console.log(cmp.testingFunction()); <--Doesn't work

I now want to be able to call functions of the lightning component when a button is pressed on my Visualforce page. just doing cmp.functionName() does not seem to work.

How do you accomplish this? I am OK triggering the AuraEnabled controller methods for the component, or the javascript controller methods.

1 Answer 1


You can use aura:method to invoke lightning controller methods as follows. Store the generated component to a global variable and invoke the aura:method to call your controller action. You can either call lightning controller methods which could, in turn, call the @AuraEnabled Methods or use RemoteActions to call your apex class methods, it really depends on your use case.


<aura:component access="global">

    <aura:method name="sampleMethod" action="{!c.doAction}" description="Sample method with parameters" access="global"> 
        <aura:attribute name="foo" type="String" default="parameter 1"/> 
        <aura:attribute name="bar" type="Object" /> 

    Inside Component



    doAction : function(component, event, helper) {
        var params = event.getParam('arguments');
        if (params) {

Visualforce Page:

<apex:page >
    <apex:includeLightning />
    <div id="lightning" />
    <script type="text/javascript">
        var cmp; 

        $Lightning.use("c:TestApplication2", function() {
            function(component) {
              cmp = component; 

        var invoke_aura_method = function(){
            cmp.sampleMethod("Hello World ! ", {message : "I'm Jack Sparrow"});


    <apex:form >
        <apex:commandButton value="Call Aura Method" onclick="invoke_aura_method();return false;"/>



Sample Aura Method


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.