How do I compare the old and new values of user license in a trigger?

When we change user licenses salesforce strips all the Permission Set assignments.

I want to copy over the permission sets when the license changes from a standard to any other platform type.

I tried :

   string olduserlicense = trigger.oldmap.get(User.id).Profile.UserLicense.Name;
   string newuserlicense = trigger.newmap.get(User.id).Profile.UserLicense.Name;
   system.debug('#####'+ olduserlicense  + newuserlicense );

Debug: 11:46:32.350 (1350392660)|USER_DEBUG|[147]|DEBUG|#####nullnull

I want to get the user license and not the type :(. Salesforce, Saleforce paltform both fall under same user type 'Standard' while userlicense have unique names:

SFDC: corresponds to the Full CRM user license

AUL: corresponds to the Salesforce Platform user license

I am sure i am missing something or doing something silly

Thanks in advance for the inputs

1 Answer 1


Try using the profile ids from the maps and query the profile for the related user licenses. I believe, the trigger map only has information about the user object not it's related objects.

  • i am tracking profile changes now, but was not sure how compare user licenses. Will wait for a bit to see if there is a way somome can think of if not will accept this as answer
    – Rao
    Commented Nov 3, 2014 at 1:11
  • Wouldn't Select Id, UserLicense.Name From Profile do the trick?
    – Jenny B
    Commented Nov 4, 2014 at 12:09
  • yes it does but my problem is when it comes to comparing the old and new values, as you mentioned user object has old and new changes related to user type and not profile.userlicense
    – Rao
    Commented Nov 4, 2014 at 14:48
  • Couldn't you create a map of profile ids to userlicense.name and use the old map profile id to retrieve the old userlicense and compare that to new map profile id userlicense?
    – Jenny B
    Commented Nov 4, 2014 at 17:59

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .