2

I'm currently working on the navigation between two custom Visualforce Pages inside the Salesforce1 Mobile App. I'm prefer to do the navigation via Apex PageReference.

public static void navigate {
   String str = 'javascript:sforce.one.navigateToSObject(\'' + Object.Id + '\')';
   PageReference pageRef = new PageReference(str);
   pageRef.setRedirect(true);
   return pageRef;
}

But it do not work for me :(

thanks

2 Answers 2

2

I doubt you'll be able to get this to work - the page reference returned from an actionfunction is the URL that the browser should send the user to, so it will be something like an HTTP response code 302 with the target URL in the headers. In that scenario, there is nowhere for the JavaScript to be interpreted and it will simply be taken as a literal URL string.

I tend to handle the navigation client side as I can then take action if the sforce.one object is undefined, which allows me to use the same pages and controller in Salesforce1, in the full UI and in a custom mobile SDK application.

3

Avoid using Pagereference methods in salesforce1 and usually i would prefer using @Remote action method to implement logic

Lets take a quick look with sample code below on how to achieve this

function actioninvoke(){
   if( (typeof sforce != 'undefined') && (sforce != null) ) {
   // Salesforce1 Remote Action method built in controller

   }
   else {
   //Action Function of normal App
   }
 }

Visualforce Code

 <apex:CommandButton value="Next" onclick="actioninvoke();" id="cmdNext" />

The advantages of remote action will be ability to callback and in callback we can use navigation specific function of salesforce1 like sforce.one

navigateToSObject(recordId,view)    //Navigates to an sObject record, specified by recordId.view is optional, and specifies the view within record home to select—chatter, related, or   detail.
2
  • 1
    Why should we avoid using PageReference methods in Salesforce1? Aug 12, 2014 at 19:07
  • 1
    You dont want the whole page refresh ?Have you seen SPA mobile apps ,they dont prefer whole page refresh Sep 16, 2014 at 4:03

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.