Apex Tip: Simplest way to detect Salesforce 1

If you are working to adapt or create a Visualforce page for Salesforce 1, you would know that you need to detect what type of client application (mobile or desktop) is doing the request.

You would need that in order to avoid certain apex:tags that are not compatible with Salesforce1, to change the layout and look and feel and code some special lines like replace links by sforce.one.navigateToSObject(objectId);

After some research I’ve found those nice methods to detect what type of client is requesting the page

Client side (Javascript):

 

Server-side (Apex):

 

3 thoughts on “Apex Tip: Simplest way to detect Salesforce 1

Leave a Reply to vanessen Cancel reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code class="" title="" data-url=""> <del datetime=""> <em> <i> <q cite=""> <strike> <strong> <pre class="" title="" data-url=""> <span class="" title="" data-url="">