Skip to content

Instantly share code, notes, and snippets.

@kiran-machhewar
Last active December 18, 2018 16:22
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save kiran-machhewar/c49f27716d007c9f2d61758ff3861c67 to your computer and use it in GitHub Desktop.
Save kiran-machhewar/c49f27716d007c9f2d61758ff3861c67 to your computer and use it in GitHub Desktop.
Permission Set
//Add Permission Sets to Users
List<User> users = [SELECT Id FROM User WHERE username in ('<USERNAME_GOES_HERE>')];
List<PermissionSet> permissionSets = [SELECT Id FROM PermissionSet WHERE Name = '<PERMISSION SET API NAMES GOES HERE>'];
List<PermissionSetAssignment> permissionSetAssignemts = new List<PermissionSetAssignment>();
for(User theUser : users){
for(PermissionSet ps : permissionSets){
permissionSetAssignemts.add(
new PermissionSetAssignment(AssigneeId = theUser.Id,PermissionSetId = ps.Id )
);
}
}
System.debug('permissionSetAssignemts-->'+JSON.serializePretty(permissionSetAssignemts));
insert permissionSetAssignemts;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment