Take the 2-minute tour ×
Salesforce Stack Exchange is a question and answer site for Salesforce administrators, implementation experts, developers and anybody in-between. It's 100% free, no registration required.

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

share|improve this question

2 Answers 2

up vote 1 down vote accepted

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.

share|improve this answer

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.
share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.