Thursday, December 18, 2014

Mass Update saleforce1 mobile field with APEX

By default, salesforce 1 Mobile browser app feature is turned on for your organization, due to this reason users will be automatically redirected to the mobile browser app view. 

Sometimes some users wish to access salesforce via mobile browser without the mobile UI. If the mobile browser feature is enabled for all the users, the users who doesn't need to see the mobile feature have to disable it manually OR the administrator has to do it. By making disable this feature for all the users we can allow them to enable this manually as their desire and vice versa.


Solution: There are several ways of doing this with the field 'UserPreferencesHideS1BrowserUI ' in the User object, this is the API name for the field label 'Salesforce1 mobile user' field. By default this field is set to false.
you can use,
1. Data Loader - How to Mass Remove/Update Salesforce1 Settings for users
2.  SOAP API - Enable the Salesforce1 Mobile Browser App
3. APEX Script (as you can see below, which I think the best way to do this quickly)


You can disable the salesforce1 mobile feature for all the users individually with an apex script, which could execute as an anonymous apex code.

  

  /**  
   *  Author: Hasantha Liyanage  
   * Created: 2014-12-15  
   * Summary: This will update the UserPreferencesHideS1BrowserUI field and make the Salesforce1 User  
   *       field on User object false  
   **/  
   // get the users who does not have salesforce1 mobile feature enabled  
   List<User> users = [  
     SELECT   
       Id,  
       IsActive,  
       UserPreferencesHideS1BrowserUI   
     FROM User   
     WHERE   
       IsActive = true   
     AND   
       UserPreferencesHideS1BrowserUI = false   
     ];  
   // make the users salesforce 1 mobile fetaure disabled individually  
   for(User user : users){  
     user.UserPreferencesHideS1BrowserUI = true;  
   }  
   update users;  

No comments:

Post a Comment