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
danathandanathan 

Is it possible to get saleforce client OS or browser type in Apex ?

My requirement is when a record is edited in web client field Data_Source__c should be set to 'WEB'.

If it is edited in mobile application then Data_Source__c should be set to 'MOBILE'.

 

We are able to set value 'MOBILE' since it is custom edit screen in mobile application. We do not know how to set it to 'WEB' since we use standard layout in web client and there is no provision to override Save button.

 

What I am thinking is if somehow I get OS or browser type in Apex, I can use it in trigger and set Data_Source__c field.

 

Please let me know if anyone can offer help for this request.

 

Nathan.

 

 

 

gautam_singhgautam_singh

Hello ,

When you login through your mobile there is a parameter USER-AGENT which passed in the URL, using this you can redirect users to specific pages.


Code Snippet:

String userAgent = ApexPages.currentPage().getHeaders().get(‘USER-AGENT’);
if(userAgent.contains(‘iPhone’)) deviceType = ‘iPhone’;{//Your iphone code goes here}
else if(userAgent.contains(‘BlackBerry’)) deviceType = ‘BlackBerry’;{//Your blackberry code goes here}

 Check this link for a code snippet.
        

Also , JavaScript is always an option to get the Browser and the current OS with its version. You can find the browser details by using javascript in your visual force page. Here is the sample code :

 

<apex:page >
<div id="browserid"></div>

<script type="text/javascript">

txt = "<p>Browser CodeName: " + navigator.appCodeName + "</p>";
txt+= "<p>Browser Name: " + navigator.appName + "</p>";
txt+= "<p>Browser Version: " + navigator.appVersion + "</p>";
txt+= "<p>Cookies Enabled: " + navigator.cookieEnabled + "</p>";
txt+= "<p>Platform: " + navigator.platform + "</p>";
txt+= "<p>User-agent header: " + navigator.userAgent + "</p>";

document.getElementById("browserid").innerHTML=txt;

</script>
</apex:page>

 



Check this blog and the w3 school link for concepts.

 

Hope this fulfills your requirement. 


Important :

Click on the Star Icon aside if this post provides you with useful information and if this is what you where looking for then please mark it as a solution for others benefits.

Thank You

danathandanathan

ApexPages.currentPage() is not working inside trigger. It is null.

We are using standard page layout in web client and visualforce page in mobile application.
No issue with visualforce page since we can set Data Source field value to Web in controller. The issue is with the web client standard page. I have to set Data Source field value only in trigger.
 

Nathan.