+ Start a Discussion
KoolABKoolAB 

Salesforce.com Lightning SetCallBack fails

I am unable to call apex class server side method from Javascript controller code for a lightning component. I have tried various options like changing return type for the apex server side method from Map to String etc but it throws error
I have even tried copying sample code given for sample expense app available on web but still SetCallBack doesnt work and error is thrown when Lightning Component is getting loaded inside Lightning app. Please let me know if anybody has faced this issue. Also let me know if we can use SOQL query to directly query custom object inside Javascript code of lightning. I have placed a button on my Salesforce.com desktop edition Case Page Layout which invokes Salesforce.com Lightning APP.
On Click of the button I want to invoke a method in apex class which makes REST API calls to some external system and updates some custom fields in Salesforce.com. When the REST API call is finished and apex code is also finished updating fields in Salesforce.com I want to receive a response from apex server side and then based on that response I want to issue a SOQL query on Custom Object of Salesforce.com from Client Side Javascript controller code of the lightning component which is used inside the lightning app. Please let me know the best way to achieve this.
Is there any way other that using Action.setCallBack to communicate between client and server

 
Shalagha GumberShalagha Gumber
Can you please share your code.

Thanks.
KoolABKoolAB
Code from my Helper Class. Pseudo Code objective is as follows
1. Apex class which creates array of Latitude and Longitude inside a method based on location
2. Call apex server side method from Salesforce.com lightning helper class get array of lat and lang and iterate it thru for loop to be used for showing positions on Map using Custom MAP API designed to take Lat and Lang as input

({//A1
    helperMethod1 : function(component)
    {//A2
    console.log('BEFORE CALLING HELPER METHOD1');
    console.log('BEFORE GETEVENT');
    var compEvent = component.getEvent("SHOWMSGEVT");
    console.log('AFTER GETEVENT BEFORE FIRING EVENT');
    compEvent.fire();
    var action = component.get("component.getLatLang()");
    action.setParams({key:"testkey1"});
    console.log('BEFORE SETCALLBACK');
    
    action.setCallback(this, function(action) {
    console.log('INSIDE SETCALLBACK FIRSTLINE');
        var str1 = action.getReturnValue();
        var Str1 = action.getState();
    //var Str1 = a.getReturnValue();
    console.log('INSIDE 12PM TESTING return value is>>>' + Str1 + '<<<');
    }
        /*
      tomtom.require(["dom/DomUtil"], function(du)
     {//A3
    console.log('AFTER TOMTOM require line');
    tomtom.setImagePath("../images/");
    console.log('AFTER TOMTOM SETIMAGEPATH');
    var action = component.get("component.WEBFLEET_SHOW_MAP.getLatLang()");
    //action.setCallback(this, function(response)
     {//A4
    var state = response.getState();
        console.log('INSIDE SETCALLBACK STATE IS>>>'+ state + '<<<<');
            if (state === "SUCCESS")
            {//A5
                console.log('INSIDE SETCALLBACK RETURNED VALUES ARE>>>'+ response.getReturnValue() + '<<<<');
                    var map = new tomtom.map({domNode:"map1",apiKey:"7fjvem9rudh39bp9zyrcbaap",
                              center: [52.373154, 4.890659],
                              cookie: true,
                            scale:true});
                console.log('AFTER TOMTOM new MAP variable creation');
                //Add map layers
                map.on("load", function() {
                    map.addLayer(new tomtom.Marker([43.26456, -71.5702]));
                    map.addLayer(new tomtom.Marker([39.73845, -104.98485]));
                    map.addLayer(new tomtom.Marker([34.05224, -118.24334]));
                    map.addLayer(new tomtom.Marker([37.78008, -122.42017]));
                });
                //end add map layers
              console.log('AFTER TOMTOM MAP ON LINE');
            }//A5
        else if (state === "ERROR")
        {//A6
                var errors = response.getError();
                if (errors) 
                {//A7
                  console.log('INSIDE ERRORS ERROR MESSAGE IS >>>' + errors[0].message + '<<<');
                    if (errors[0] && errors[0].message)
                    {//A8
                        console.log("INSIDE Error message: " +
                                 errors[0].message);
                    }//A8
                }//A7
            else {//A9
                    console.log("Unknown error");
                }//A9
         }//A6
     }//A4
         
   /*
    // create the second map
                var map2 = new tomtom.Map({
                    domNode: document.getElementById("map2")
                });
                 // create a function to toggle a map on or off
                function toggleMap(id, map)
                {
                    console.log('INSIDE TOGGLE MAP FUNCTION CALL');
                    // if the map is defined, destroy it (toggle off)
                    if (map) {
                        console.log('INSIDE IF STATEMENT OF TOGGLEMAP');
                        map.destroy();
                        return null;
                    // otherwise, create a new map (toggle on)
                    } else {
                       console.log('INSIDE ELSE PART STATEMENT OF TOGGLEMAP');
                        return new tomtom.Map({
                            domNode: id,
                            cookie: true
                        });
                    }
                }
           // on click of each button, toggle the corresponding map
         du.query("#mapToggle1").on("click", function() { map = toggleMap("map1", map); });
           du.query("#mapToggle2").on("click", function() { map2 = toggleMap("map2", map2); });*/
    //});*/
    }//A3*/
         }//A2
})//A1
Peter Kamp1Peter Kamp1
Hi,

You have created actions but not queued them with: $A.enqueueAction(Action);

KoolABKoolAB
It was copy paste error. I have used EnqueAction inside my code.