+ Start a Discussion
Eyal Hutter 1Eyal Hutter 1 

remote action is invoked but not returned to handler function


I have a visualforce component that is calling the remote action "insertAllRecords" in the controller by clicking a button and as I seen there is a strange behaviour:
Sometimes when I click the button the remote action is doing all the function code and returning to the handler but sometime it is just doing the code without returning to the handler. I saw on the debug log that all the code worked successfully without errors, also checked the chrome browser console and ther are no errors there. I have a jquery.noconflict() call and I tried to isolate the call to the remote action from the rest of the visualforce page and the behaviour hasn't changed.

at the handler there should be redirecting to a different page but that is not happening all the time and the console.log too that I have.

It looks like a conflict or a bug in salesforce but it is not showing any error.

Here is the code of the javascript:

function ajaxPost(listToInsert) {
                var campaignId = '{!campaignId}';
                var objectType = '{!typeObject}';
                var allIdsString = listToInsert;
                allIdsString = allIdsString.substring(1, allIdsString.length-1);
                var allIdsArray = allIdsString.split(",");
                console.log('campaignId: ' + campaignId);
                console.log('allIds: '  + allIdsArray);
                console.log('objectType: ' + objectType);
                vfTableGenerate.insertAllRecords(campaignId, allIdsArray, objectType,
                function(result, event){
                    if (event.status) {
                       top.window.location = result;

the visualforce button:

<apex:commandButton value="Add To Campaign Members" onclick="ajaxPost('{!recordToInsertList}');"/>

Any help will be great!
Salesforce Javascript remote action is asynchronous, so the execution of handler depends a lot on when Salesforce sends response.
Eyal Hutter 1Eyal Hutter 1
But even if this is asynchronous, isn't there suppose to be a redirecting eventually where I have the top.window.loacation? The first line of the handler is not showing the console log "111" after waiting minutes in cases that the handler is not called back, nor redirecting.
The funny thing is that the handler is not called only if you call the remote action in the first time. In the second time and so on it works!

Can someone please help to find a solution?

More info: I'm using the remote action in a apex component with a jquery data table.