+ Start a Discussion
SimrinSimrin 

Detecting Salesforce1

<apex:pageBlockSection title="Test" columns="{!columns}">

I have columns value coming from controller.

I want to do something like if(displayed In == Salesforce1, 2 columns, Or display "columns"  for desktop)

 

Best Answer chosen by Simrin
Sampath KumarSampath Kumar
Hi Simrin,

Below is the class which gives result true when it is opened in salesforce 1 else return false, so based on true or value you can write your code in visualforce page.

public static Boolean getRedirect(){
    if(String.isNotBlank(ApexPages.currentPage().getParameters().get('sfdcIFrameHost')) ||
        String.isNotBlank(ApexPages.currentPage().getParameters().get('sfdcIFrameOrigin')) ||
        ApexPages.currentPage().getParameters().get('isdtp') == 'p1' ||
        (ApexPages.currentPage().getParameters().get('retURL') != null && ApexPages.currentPage().getParameters().get('retURL').contains('projectone') )
    ){
        return true;
    }else{
        return false;
    }
}

Let me know if this helps.

Regards
Sampath Kumar Goud

All Answers

Sampath KumarSampath Kumar
Hi Simrin,

Below is the class which gives result true when it is opened in salesforce 1 else return false, so based on true or value you can write your code in visualforce page.

public static Boolean getRedirect(){
    if(String.isNotBlank(ApexPages.currentPage().getParameters().get('sfdcIFrameHost')) ||
        String.isNotBlank(ApexPages.currentPage().getParameters().get('sfdcIFrameOrigin')) ||
        ApexPages.currentPage().getParameters().get('isdtp') == 'p1' ||
        (ApexPages.currentPage().getParameters().get('retURL') != null && ApexPages.currentPage().getParameters().get('retURL').contains('projectone') )
    ){
        return true;
    }else{
        return false;
    }
}

Let me know if this helps.

Regards
Sampath Kumar Goud
This was selected as the best answer
sandeep sankhlasandeep sankhla
Hi Simrin,

Hi you can simply identify if page is openendd in SF1 or SF then accordingly you cna render the section..

In my case I haev used 2 different pages and redirect to them based on SF and SF1..

You can refer the below code to identify..

 window.onload = function redirectToDestinationPage()
            {
                if( (typeof sforce != 'undefined') && (sforce != null) ) {
            
                    window.$j = jQuery.noConflict();
                    $j( document ).ready(function() {
                    Uehi_beta.uniqueEntryNavigationController.getRecordTypesList('Account',function(result, event){
                                
                        if(result .length == 0)
                        {
                            var base_url = window.location.origin;
                            sforce.one.navigateToURL(base_url +'/apex/Uehi_beta__uniqueAccountSF1Version');
                        }
                        else if(result.length == 1)
                        {    
                            var base_url = window.location.origin;
                            sforce.one.navigateToURL(base_url +'/apex/Uehi_beta__uniqueAccountSF1Version?RecordType='+result[0].Id);
                        }
                        else
                        {
                            var RecordTypes = '';
                            for(var index=0 ; index < result.length; index++)
                            {
                                
                                RecordTypes += '<input type=button class="btn" id='+result[index].Id+' onclick="redirectToAccNewLayout(this)" value="'+ result[index].Name+'" /> '
                                RecordTypes += '<br>';
                                console.log('RecordTypes = ',RecordTypes);
                            }
                    
                                            
                        document.getElementById('RecTypepopUp').innerHTML = RecordTypes ;
                        
                        document.getElementById('Click').click();               
                    }
                    
                    });
              });
            }
            else {
                window.location.href = '/apex/Uehi_beta__uniqueAccount';
            }
        }


Please mark this as best answer if it helps you.