how to check the page is loaded in mobile or browser using Apex Class

its achievable with the help of “User-Agent” header properties like below:


String userAgent = ApexPages.currentPage().getHeaders().get('User-Agent');
if (userAgent.contains('iPhone')) {
    return 'iPhone-Safari';
} else if (userAgent.contains('iPad')) {
    return 'iPhone-Safari';
} else if (userAgent.contains('Salesforce')) {
    return 'Salesforce';
} else if (userAgent.contains('BlackBerry')) {
    return 'BlackBerry';
} else {    
    return 'other';



Written by 

2x Salesforce MVP | Platform Champion | 18x Salesforce Certified | MuleSoft Certified | 8x Trailhead Ranger | TechForce Services | Sydney | Australia

Leave a Reply

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