function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
Chirag Sapkota 5Chirag Sapkota 5 

Is it Possible to auto assign data.com licenses with 300 limit to newly created users? If yes, How can it be done?

Hello Everyone, 
Is it Possible to auto assign data.com licenses with 300 limit to newly created  users? If yes, How can it be done? Triggers? Process builder? 
Thank you for your help
Best Answer chosen by Chirag Sapkota 5
Abhishek BansalAbhishek Bansal
Hi Chirag,

Yes, you can achieve this with the help of a trigger. Please find help from the below sample code:
PackageLicense psePackageLicenseRecord = [SELECT Id FROM PackageLicense where NamespacePrefix = 'data.com'];//Replace data.com with the licence name
UserPackageLicense newUserPackLicRecord = new UserPackageLicense();
newUserPackLicRecord.PackageLicenseId = psePackageLicenseRecord.Id;
newUserPackLicRecord.UserId = userId; //This is the user id of the newly created user.
insert newUserPackLicRecord;
You can use the above code inside your before insert trigger for the user object. Please let me know if you need any further help on this.

Thanks,
Abhishek Bansal.