3

Callback functions have been behaving very strangely and I am not sure if I am getting this correct. I have a remoting function which is update records in data base and have just kept a alert on the callback.

But I dont see the alert coming up consistently, 1 out of 5 times it fails to show the javascript alert meaning the callback didnt happen for some reason.

function InsertOrganisation(Name,AddressLine1,AddressLine2,AddressLine3,AddressLine4,City,Country,AliasName,PostalCode,StateOrProvince,BusinessID,RowID,WebsiteURL)
        {   
            Visualforce.remoting.Manager.invokeAction(
                '{!$RemoteAction.Organisation_Lookup.InsertOrganisation}',
                Name,AddressLine1,AddressLine2,AddressLine3,AddressLine4,City,Country,AliasName,PostalCode,StateOrProvince,BusinessID,RowID,WebsiteURL,
                function(result, event){
                   alert('Inside Callout'+result.Id);
                }, 
                {buffer: false,escape: false}
            );
        }  

If you see the alert('Inside Callout'+result.Id) is inconsistent in showing up and shows only most of times. I though callback are synchronous and surely will be triggered, am i missing anything?

Below is the controller of the remoting, I am not performing any compex logic but just upserting the data that i get in the remote call. Why is the callback alert not showing up all the time correctly?

@RemoteAction
    global static Organization__c InsertOrganisation(String Name,String AddressLine1,String AddressLine2,
                                                            String AddressLine3,String AddressLine4,String City,String Country,
                                                            String AliasName,String PostalCode,String StateOrProvince,String BusinessID,String RowID,String WebsiteURL){
        Organization__c oOrganisation = new Organization__c();
        oOrganisation.Name = Name;
        oOrganisation.Address_1__c = AddressLine1;
        oOrganisation.Address_2__c = AddressLine2;
        oOrganisation.Address_3__c = AddressLine3; 
        oOrganisation.Address_4__c = AddressLine4;
        oOrganisation.City_Name__c = City;
        oOrganisation.Country__c = Country;
        oOrganisation.Organization_Alias_name__c = AliasName;
        oOrganisation.Postal_Code__c = PostalCode;
        oOrganisation.State_Province__c = StateOrProvince;
        oOrganisation.Organization_Business_ID__c = BusinessID;
        oOrganisation.Org_Row_ID__c = RowID;
        oOrganisation.Web_Site__c = WebsiteURL;

        Upsert oOrganisation Organization_Business_ID__c;
        return oOrganisation;

    }
  • Are you getting any console messages in either case? – Adrian Larson Mar 13 '16 at 23:30
2

Callbacks are not synchronous and Javascript remoting is always asynchronous .The callbacks happens once the response is received from the server .

Also making buffer=false does not imply that the process will become synchronous .By default the buffer is true meaning if there are same type of requests happening the request is grouped together before sending to server .

With buffer=false the request is sent individually and each request is being made.

Is your remote action invoked on button call or page load ? There might be another javascript function failing leading to silent failures . You can debug via debug logs to see how many times your backend logs appear which would confirm the no of times the request was sent to the server .

Also open up console or the network tab in chrome to count if request made through SFDC servers or was blocked due to failures .

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.