How to call visualforce page in Salesforce1

H

Its pretty easy:

<apex:page>
    <script>
        try
        {
            sforce.one.navigateToURL('/apex/myVFPage');
        }
        catch(e)
        {
            window.location.href = '/apex/myVFPage';
        }
    </script>
</apex:page>

But you would come to a problem eventually that the vf page where I wrote above code, suppose testSF1 … how do I call that page?

Here is manual way:

1. Create new visualforce tab for this testSF1 page.

2. Goto Setup -> Mobile Adminstration -> Mobile Navigation -> Add the tab to available list -> Save.

3. Open Salesforce1 app & you’ll find the tab in the left menu list.

 

Here is another way of automatically invoking the visualforce page in salesforce1 format:

1. Create new visualforce tab for this testSF1 page.

2. Goto Setup -> Mobile Adminstration -> Mobile Navigation -> Add the tab to available list -> Save.

3. Open Salesforce1 in mobile browser (e.g. https://na15.salesforce.com/one/one.app). Login & you’ll see similar view as that of app. Now from the left menu, click on your vf page tab.

4. Note the address bar url is changed to something like:

https://na15.salesforce.com/one/one.app#eyJjb21wb25lbnREZWXiOiJvbmU6YWxvaGFQYWdlIiwiYXU0cmlidXRlcyI6eyJ2YWx1ZXMiOnsiYRRkcmVzcyI6Imh0dHBzOi8vZW1haWxjb25uZWN0Lm5hMTUudmlzdXFsLmZvcmNlLmNvbS9hcGV5L0VtYWlsQ29ubmVjdF9DYWxsU0YxP3NmZGMudGFiTmFtZT0wMXJpMDAwMDAwMG9ldDUifX0sInQiOjEzOTU2ODIzMDQwNTJ9

5. Copy this url & you can directly call this URL to open the vf page directly wherever you want.

 

Now here is one very weird behavior of URLs getting generated in Salesforce1:

Suppose your vf page code is:

<apex:page controller="EmailConnect_GotoIdController">
    <script>
        try
        {
            sforce.one.navigateToSObject('{!recId}');
        }
        catch(e)
        {
            window.location.href = '/{!recId}';
        }
    </script>
</apex:page>

Now if you follow my above method of creating/adding tab, opening SF1 in mobile browser & copying the URL …. this I am afraid wont work everytime. Based on the contents the URL dynamically changes if the content is Dynamic. Here is what I mean:

– Suppose {!recId} passed to vf page was 003i000000ZjE8T then URL of tab would be different.

– Suppose {!recId} passed to vf page was 003i000000ERbAg then URL of tab would be different though tab is same.

 

This is really strange & annoying for programmers but seems no solution yet. So to solve this problem, we have devised solution of our own. Contact us through http://www.nanostuffs.com & we’ll be more than delighted to help you.

About the author

Nishant Bamb
By Nishant Bamb

Category