PackageLicense license = [SELECT Id FROM PackageLicense WHERE NamespacePrefix = 'vlocity_ins' LIMIT 1]; List<String> lstProfile = new List<String>{'Gerente C6 Empresas - Básico','Gerente Alta Renda - Básico'}; List<UserPackageLicense> pckLicenseToUsers = new List<UserPackageLicense>(); List<User> usersBusinessAndAr = [SELECT Id, Username, LastName, FirstName, Name, UserRoleId, ProfileId, Profile.Name FROM User where Profile.Name IN :lstProfile]; for (User usr : usersBusinessAndAr){ pckLicenseToUsers.add(new UserPackageLicense(UserId = usr.Id, PackageLicenseId = license.Id)); } Database.SaveResult[] sr = Database.insert(pckLicenseToUsers); System.debug('SR: ' + sr);
Preview:
downloadDownload PNG
downloadDownload JPEG
downloadDownload SVG
Tip: You can change the style, width & colours of the snippet with the inspect tool before clicking Download!
Click to optimize width for Twitter