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
sivaextsivaext 

We have developed hybrid IOS mobile app but facing loading issue if phone is idle for some time, ex: search for account , create new account etc? We have written javascript remote action to fetch the results. I din't find any debug log in system

Hi All, 

We have developed IOS mobile app but facing loading issue if phone is idel for some time. The app is working once logout from apps and re login into app.  

ex: we are facing issue when search for account, new account creation etc. 

We have used javascript remote action to fetch the results .
please see sample code

@RemoteAction
        global static List<Account> fetchAccountDetails(String name) {
            //system.assertEquals('fd','jk');
            // where Name LIKE \'%\''+name+'\'%\'
            String qry = 'Select Id,Name,BillingStreet,BillingCity,BillingCountry,BillingState,BillingPostalCode,FloraMobileApp__LGA_Name__c,FloraMobileApp__Stage__c,FloraMobileApp__Total_Order_Arrangements__c,FloraMobileApp__Trial_Arrangements__c,Industry,(Select Salutation,Name,Phone From Account.Contacts) From Account where Name LIKE \'%'+name+'%\' LIMIT 10 ';
            return database.query(qry);
        }

Please help me.

Regards
Siva.
Best Answer chosen by sivaext
bob_buzzardbob_buzzard
So is the issue that the user's session has expired? Check out this section of the mobile app developers guide:

https://developer.salesforce.com/docs/atlas.en-us.186.0.salesforce_platform_mobile_services.meta/salesforce_platform_mobile_services/hybrid_managing_sessions.htm

scroll down to the JavaScript Remoting in Visualforce section and that shows how to trap an expired session and refresh it.

All Answers

bob_buzzardbob_buzzard
So is the issue that the user's session has expired? Check out this section of the mobile app developers guide:

https://developer.salesforce.com/docs/atlas.en-us.186.0.salesforce_platform_mobile_services.meta/salesforce_platform_mobile_services/hybrid_managing_sessions.htm

scroll down to the JavaScript Remoting in Visualforce section and that shows how to trap an expired session and refresh it.
This was selected as the best answer
sivaextsivaext
Hi Bob,

Thanks for you reply.

I tried to reload the page using window.location.reload(), it is working fine.

I am trying to increase performance using other snippet code in mobile sdk pdf but i am not clear couple places.

// Refresh oauth token
cordova.require("salesforce/plugin/oauth").authenticate(
  function(creds) {
   // Reload hidden iframe that points to a blank page to
   // to refresh Visualforce domain cookies
   var iframe = document.getElementById("blankIframeId");
   iframe.src = src;
 
   // Refresh CSRF cookie
   <provider>.refresh(function() {
     <Retry call for a seamless user experience>;
   });

  },
  function(error) {
    console.log("Refresh failed");
  }
);

can you please explain, what is <provider> here?  i read below lines in some blog , is it true to required case to enable CSRF?

I logged a case for this as I was able to perform CSRF hacks against methods annotated with @RemoteAction and the response is:

This is not enabled by default. You have to contact salesforce to get CSRF protection for Remote Actions turned on.

Can you please give small example for above code?

Thanks & Regards
Siva.

bob_buzzardbob_buzzard
I haven't used that side of things I'm afraid.  Best bet is to post to the mobile discussion board at : https://developer.salesforce.com/forums?communityId=09aF00000004HMGIA2#!/feedtype=RECENT&dc=Mobile&criteria=ALLQUESTIONS
sivaextsivaext
Thank you bob , i will do 
Pault.ax256Pault.ax256
@sivaext Hi there - did you get anywhere.  Am facing the same issue myself and refreshing the entire page in the middle of the user using the app does not give the best user experience.  Did you figure out what <provider>.refresh() means/does or how to do it.  Thanks in advance !
Todd Halfpenny 9Todd Halfpenny 9
Hi all,

I found an old github post... and it seems to point to using one of the providers returned by this;
Visualforce.remoting.Manager.providers

In saying that, I tried to log this out (using JSON.stringify) and it has circular relationships so I actually went with the following and am having some success with it;
var vfProvider = Visualforce.remoting.last;
vfProvider.refresh(function() {
     console.log('some sort of success');
});

I'm still unable to find any absolute documentaion on this, and sadly I also can't find an un-uglified vfremote.js so it's hard to reverse engineer too.