+ Start a Discussion
rahma bhbrahma bhb 

callback only called when developer tools/ Lightning components

I am calling a method saveData from my js controller when all the fields of my form are filled :
            rules: {
                title: {required: true},
                firstname: {required: true},
                lastname: {required: true},
            messages: {
                title:  "Please type and select a title",
                firstname: "Please enter the client first name",
                lastname: "Please enter the clients last name",
                '_all_': {placement: 'top'},
            focusInvalid: false,
            submitHandler: function() {
                if($('#confirmation').prop("checked") == false ){
                }else {

The callback of this method is never called - and when I open the developer tools , the callback function is called and working fine
saveData: function(component){
        var action = component.get("c.saveClient");
            "firstname": firstname,
            "lastname": lastname,
            "title": "title"
        action .setCallback(this, function(response){
            var state = response.getState();
            if (component.isValid() && state === "SUCCESS") {
                alert('inside the callback');

does any one has an explanation of why the code is only working when open the developer tools in the browser please?
Veena Sundara-HeraguVeena Sundara-Heragu
I am not suer why that is, but there seems to be an error in your code:

you have named your variable as "action" in this line:
       var action = component.get("c.saveClient");
In the next line you are referring it by the name "actionJInsured" instead of action.
rahma bhbrahma bhb
Hi  Veena Sundara-Heragu,
Thank you for your reply
This did not solve the issue sadly, the callback function does not seem to be entered at all
Not sure if this is a bug in Salesforce Lightning as when I open the developer tool all the code inside the callback
is executed and works fine.
Veena Sundara-HeraguVeena Sundara-Heragu
Hi Reshma

I just noticed a space between action and .setCallback.  I think that is the problem.  it needs to be 
rahma bhbrahma bhb
Hi Veena, 
Thank you for getting back to  me
Not solving the issue either, 
When I call this method when I click the button it works fine (without opening the developer tool) 
and when I call the same method from the submit handler (form validation), then it does not work (and works when I
open the developer tool) - have you had any similar issue before ?
Veena Sundara-HeraguVeena Sundara-Heragu
You have said that is does not enter the callback.  Do you know if it is executing the saveClient method ?  Is that an apex method ?  By any chance do you also have a method in your js controller with the same name ?
rahma bhbrahma bhb
nope - the apex function and the js function have different names ,
besides, it enters the saveClient method and does not enter the callback - and again if inspect the code and open the
developer tool the code continue to execute - it seems like it is blocked at this stage for some reason