All posts

VisualForce in Salesforce1

Salesforce1 is the mobile platform of Salesforce which enables the user manage their leads and all other data on their mobile devices. For some custom functionality we will have to create VF page but the VF page should be mobile compatible. For Example: A VF page, with some custom functionalities, has been placed on click of Account New button and the same functionality is required in Salesforce1. Then a new VF page will be built which will mobile compatible and lighter using jQueryMobile, BootStrap etc.

Now here comes the tricky part: How will the New button know which page to choose - Desktop or Mobile version?

For this purpose Salesforce1 Navigation comes into play. When the user is using Salesforce1 mobile app then "sforce.one" JS object is created. So we can write a JavaScript code to check whether this object is Null or not.

<script>
function getMediaType()
{
if(sforce.one == Null || sforce.one == 'undefined')
{
var mediaType = 'Desktop';
}
else
{
var mediaType = 'Salesforce1';
}
return mediaType;
}
</script>

Now pass this mediaType variable into your controller using ActionFunction & Param and write the redirection code accordingly.

First published on Blogger in 2015. Some screenshots and APIs have changed since; the code is kept as written.

  • jQueryMobile
  • responsive
  • Salesforce
  • Salesforce1
  • VF Page salesforce1 app
  • visualforce page