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
Deepu Gupta 29Deepu Gupta 29 

VF page is working fine in Browser but not in SF1

Hi All,
I have created a link in Account Hierarchy(inline VF Page) Section under Account Detail Page which is navigating me on another page where this whole Hierachy shown and two other links are given which is navigating me on another VF page its working fine in browser but not working in SF1.Navigating code is written in this controller which i am sharing.I have enable the checkbox in VF page to Available for Salesforce mobile apps and Lightning Pages.
<apex:page standardController="Account" tabStyle="Account" extensions="WithContactButtonController">
<apex:form >
<apex:pageBlock > 
<apex:pageBlockSection title="Account Hierarchy" columns="2">


<c:HierarchyTree currId="{!Account.id}" />



</apex:pageBlockSection>
</apex:pageBlock>

<script>
     var url = location.href;
     var match = url.match(/inline=1/);
    if (match != null) { 
        var newUrl = url.replace(/inline=1/, '');
        window.top.location=newUrl;
    }
</script>
<table align ="centre">
<tr>
<td><b><apex:commandLink action="{!Cancel}" target="_top" value="BacktoAccount" id="theButton1"/></b></td>
<td></td>
<td></td>             
<td><b><apex:commandLink action="{!IncludeContactpage}" target="_top" value="IncludeContact" id="theButton"/></b></td>
</tr>
</table>


</apex:form>
</apex:page>

public with sharing class WithContactButtonController
{
    private ApexPages.StandardController standardController;
    public Id currId= apexpages.currentpage().getparameters().get('Id');

    
    public WithContactButtonController(ApexPages.StandardController standardController)
    {
        this.standardController = standardController;
        
    }
    public PageReference renderforShowAccHierarchy()
    {
        // Apex code for handling record from a Detail page goes here
        //Id recordId = standardController.getId();
        //PageReference pageRef = new PageReference('/apex/HierarchyPage1?retURL=/apex/HierarchyPage?Id='+standardController.getId());
         PageReference pageRef = new PageReference('/apex/HierarchyPage1?Id='+currId);
         pageRef.setRedirect(true);
         return pageRef ;
    }
    public PageReference IncludeContactpage()
    {
        // Apex code for handling record from a Detail page goes here
        PageReference pageRef1 = new PageReference('/apex/Hierarchy_Clone?Id='+currId);
        pageRef1.setRedirect(true);
        return pageRef1;

    }
    
}


User-added image

User-added image
Veenesh VikramVeenesh Vikram
If you are having issues in Navigation in SF1, use sforce.one Object.
Like:
'javascript:sforce.one.navigateToURL(url)';

Refer: https://developer.salesforce.com/docs/atlas.en-us.salesforce1.meta/salesforce1/salesforce1_dev_jsapi_sforce_one.htm

Hope this helps

Veenesh
Deepu Gupta 29Deepu Gupta 29
I have already gone through this article but not sure how to use it in my code.could you please suggest?
Veenesh VikramVeenesh Vikram
Dont use controler to redirect, instead use javaScript.

You can check if the page is open in SF1 or not by using below code in javaScript and then open the Page accordingly:
//If open in SF1
if( (typeof sforce != 'undefined') && (sforce != null) ) {
    sforce.one.navigateToURL('/apex/HierarchyPage1?Id='+currId);
}
//If open in browser
else{
    window.open('/apex/HierarchyPage1?Id='+currId);
}

Include above code in a JavaScript function and call the same onclick of hyperlink.

 
Deepu Gupta 29Deepu Gupta 29
Hi Veenesh,
I have written the code which you shared in the onclick javascript of the command link that is Include Contact which is there in Hierarchypage1 and suppose to navigate me on Hierarchy_Clone page.but still i am not able to see this link in my sf1.the code which i modified in HierarchyPage1 is as follows :
<apex:page standardController="Account" tabStyle="Account">
<apex:form >
<c:HierarchyTree currId="{!Account.id}" />
<table align ="centre">
<tr>
<td><b><apex:commandLink target="_top" value="IncludeContact" id="theButton"/></b></td>
</tr>
</table>
</apex:form>
</apex:page>
Please let me know how to get visible that link in sf1.
 
Virendra ChouhanVirendra Chouhan
Hi Deepika,

@Veenesh Vikram is 100% correct. Use JS to redirect instead of controller method. PFB code snippet 
<apex:page standardController="Account">
  <apex:form >
	<apex:commandLink value="GoToInlinePage" onclick="redirect();"/> 
	<!--   <apex:commandLink value="GoToInlinePage" onclick="window.open('/apex/inlineAccountPage','_parent')"/> -->
  </apex:form>
  <script>
   function redirect(){
      var accId = '{!$CurrentPage.parameters.Id}';
      //If open in SF1
        if( (typeof sforce != 'undefined') && (sforce != null) ) {
         sforce.one.navigateToURL('/apex/inlineAccountPage?id='+accId);
        }
        //If open in browser
        else{
        window.open('/apex/inlineAccountPage?id='+accId,'_parent');
        }
       } 
  </script>
</apex:page>

Note: I have used accountID from the URL, replace it with your variable.

Thanks & Regards,
Viru
Deepu Gupta 29Deepu Gupta 29
Thanks for your reply viru,But i am still having the same issue.I have just copy pasted your code like this :
<apex:page standardController="Account">
  <apex:form >
  <c:HierarchyTree currId="{!Account.id}" />
    <apex:commandLink value="IncludeContact" onclick="redirect();"/> 
    <!--   <apex:commandLink value="GoToInlinePage" onclick="window.open('/apex/inlineAccountPage','_parent')"/> -->
  </apex:form>
  <script>
   function redirect(){
             
              if( (typeof sforce != 'undefined') && (sforce != null) ) {
         sforce.one.navigateToURL('/apex/Hierarchy_Clone?id='+currId);
        }
                }
       } 
  </script>
</apex:page>

User-added image
User-added image
Still i am not able to see this link in my sf1.
User-added image
Deepu Gupta 29Deepu Gupta 29
Still link is visible in Browser but not in SF1.let me know if any change needs to be done at the time of link creation.