+ Start a Discussion
Naresh Krishna.ax1176Naresh Krishna.ax1176 

How to get the OS name in salesforce apex ?

Hi All,

 

We can login to salesforce from any OS like Windows, IMac, Android, etc.

I need to do some specific task based on the logged in user's OS.

 

Can any one please help me with this.

 

Thanks.

Marty Y. ChangMarty Y. Chang

Hello, Naresh,

 

I believe what you're trying to do is called "browser detection".  A quick search on Google can get you started: http://google.com/search?q=browser+detection

 

Alternatively you can try searching for "browser os detection".  I can't recommend any specific scripts or libraries, so I'll let you look around and try some options to see what you like.  Good luck!

sfdcfoxsfdcfox

ApexPages.currentPage().getHeaders().get('User-Agent')

 

Not 100% reliable, though (depends on what the browser is willing to submit to the server about your experience). You may also have additional headers available from mobile devices.

 

Try using the following page for diagnostics:

 

<apex:page controller="headertest">
    <table>
        <tbody>
            <apex:repeat value="{!headers}" var="key">
                <tr>
                    <th>{!key}</th>
                    <td>{!headers[key]}</td>
                </tr>
            </apex:repeat>
        </tbody>
    </table>
</apex:page>

 

public with sharing class headertest {
    public map<string,string> headers { get { return apexpages.currentpage().getheaders(); } set; }
}