1

in Salesforce 1 its not redirecting to the correct record page in Salesforce 1 but is instead redirecting to the Standard Salesforce Web Browser version of the page.

Here is the code:

            <div id="center" onclick="myFunction()">
               <apex:image value="{!$Resource.Submit}" styleClass="button"/>
            </div>

        <script type='text/javascript'>  
            Sfdc.canvas.publisher.subscribe({name: 'publisher.post', onData:function(e) {
                insertSignature();
            }});                                           
        </script>
        <script>
          (function(i,s,o,g,r,a,m){i['GoogleAnalyticsObject']=r;i[r]=i[r]||function(){
            (i[r].q=i[r].q||[]).push(arguments)},i[r].l=1*new Date();a=s.createElement(o),
            m=s.getElementsByTagName(o)[0];a.async=1;a.src=g;m.parentNode.insertBefore(a,m)
          })(window,document,'script','//www.google-analytics.com/analytics.js','ga');

          ga('create', 'UA-36269828-12', 'salesforce.com');
          ga('send', 'pageview');

        </script>
    </body>
</html>
<script>
    function myFunction(){

 if( (typeof sforce != 'undefined') && (sforce != null) ) {
    // Salesforce1  
    alert("made it");
   var recordId = 'a04B00000011w41IAA';
   var type = 'detail';
   sforce.one.navigateToSObject(recordId, type);        
 } else {
    // Desktop
   window.location.href = '/a04B00000011w41IAA';
    }   
}
4
  • Obvious questions, but you're testing this in one.app? Try going to your console, selecting the VF frame, and entering sforce.one.navigateToSObject('a04B00000011w41IAA', 'detail');
    – greenstork
    Commented Oct 2, 2014 at 18:35
  • Yeah I entered that into the console and it said Uncaught TypeError: Cannot read property 'navigateToSObject' of undefined
    – user5428
    Commented Oct 2, 2014 at 19:40
  • Visualforce pages sit in an iframe in one.app, are you sure your console was in the VF frame and not the top frame?
    – greenstork
    Commented Oct 2, 2014 at 19:54
  • In case others are having problems with this one too.. I was having a similar problem, then realized I was using the wrong case. I was using navigateToSobject instead of navigateToSObject (note the lower vs. upper case O). Commented Nov 3, 2015 at 21:11

1 Answer 1

1

On this line in your code:

sforce.one.navigateToSObject(recordId, type);

Try omitting the second parameter and just use:

sforce.one.navigateToSObject(recordId);
5
  • @user5428, Please Mark it as answer if it works for you. Thanks. Commented Oct 4, 2014 at 4:16
  • Any updates? Did it work for you? Commented Oct 6, 2014 at 1:37
  • 2
    I finally figured it out. If you use window.location at any point within the SF1 app Salesforce 1 Mobile navigation fails to work through the rest of the clickpath. I was using window.location to redirect from my first VF to another VF page and then using sforce.one.navigation after that. After changing the initial redirect to be through sforce.one.navigation everything worked.
    – user5428
    Commented Oct 7, 2014 at 18:00
  • Unfortunately I didn't see this anywhere in the documentation or online.
    – user5428
    Commented Oct 7, 2014 at 18:02
  • 3
    @user5428 you should post that as an answer then to help people who have this problem in the future.
    – Adrian Larson
    Commented Feb 13, 2015 at 16:34

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .