2

I'm trying to update the User field "Salesforce1 User" (API Name = UserPreferencesHideS1BrowserUI /Boolean) programmatically in a user Trigger (Before Insert, Before update). I'm trying to disable Salesforce1 for a certain user profile. Here is the code:

trigger User_AIU_Set_SF1 on User (before insert, before update) {

for(User u : Trigger.new) {

  if( u.ProfileId == '00eD0000001oOLN'){
      u.UserPreferencesHideS1BrowserUI = true;
      u.CompanyName = 'test';       
  }
}  ///
}

Unfortunately the field UserPreferencesHideS1BrowserUI is not updated. For testing purposes that the trigger generally works, I updated also the user field Company in the trigger. This update works within the same trigger.

Why is UserPreferencesHideS1BrowserUI not updated and how can I accomplish this ?

-1

Since you say the CompanyName change is working, try modifying your code as below:

boolean b = true;
for(User u : Trigger.new) {

  if( u.ProfileId == '00eD0000001oOLN'){
      u.UserPreferencesHideS1BrowserUI = b;
      u.CompanyName = 'test';       
  }
}  ///

Also, make certain your trigger is saved in API version 29.0 or later.

I should add that whoever is running the trigger should have the “Manage Internal Users” permission. Additionally, if the user being edited/inserted is a Customer Portal user, the User running the trigger will need to have the “Edit Self-Service Users” permission, and if the user being edited/inserted is a partner portal user, they must have the “Manage External Users” permission for this to take effect since the trigger will likely run in the context of the editing User's permissions.

  • Why would assigning a Boolean variable work over assigning true directly? This answer makes no sense, and wouldn't fix anything. Also, triggers don't generally care about user permissions. They execute in system context. – sfdcfox Apr 14 '15 at 18:27

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.