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 

Salesforce MVP | Lightning Champion | 17x Salesforce Certified | Application Architect | 7x Trailhead Ranger | Techforce Services | Australia

Leave a Reply

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

*