function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
KoolABKoolAB 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 desktop edition Case Page Layout which invokes 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 When the REST API call is finished and apex code is also finished updating fields in 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 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.

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 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

    helperMethod1 : function(component)
    console.log('BEFORE GETEVENT');
    var compEvent = component.getEvent("SHOWMSGEVT");
    var action = component.get("component.getLatLang()");
    console.log('BEFORE SETCALLBACK');
    action.setCallback(this, function(action) {
        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)
    console.log('AFTER TOMTOM require line');
    var action = component.get("component.WEBFLEET_SHOW_MAP.getLatLang()");
    //action.setCallback(this, function(response)
    var state = response.getState();
        console.log('INSIDE SETCALLBACK STATE IS>>>'+ state + '<<<<');
            if (state === "SUCCESS")
                console.log('INSIDE SETCALLBACK RETURNED VALUES ARE>>>'+ response.getReturnValue() + '<<<<');
                    var map = new{domNode:"map1",apiKey:"7fjvem9rudh39bp9zyrcbaap",
                              center: [52.373154, 4.890659],
                              cookie: 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');
        else if (state === "ERROR")
                var errors = response.getError();
                if (errors) 
                  console.log('INSIDE ERRORS ERROR MESSAGE IS >>>' + errors[0].message + '<<<');
                    if (errors[0] && errors[0].message)
                        console.log("INSIDE Error message: " +
            else {//A9
                    console.log("Unknown error");
    // 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');
                        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); });*/
Peter Kamp1Peter Kamp1

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

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