Atribui licenças Vlocity ao um grupo de usuários Gerentes Ar e C6 Empresas.

PHOTO EMBED

Wed Aug 02 2023 19:18:21 GMT+0000 (Coordinated Universal Time)

Saved by @peron97 #apex

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);
content_copyCOPY