+ Start a Discussion
Mohan SFDC 25Mohan SFDC 25 

Assign permission set through vf page

Hello Eveyone,

I have created a visualforce page, in that I have a user lookup field and a button 
after selecting user, when I click on submit button I want to assign a permission set to that user(custom permission set). 
please help me on this.
Please telle me how to approach this.

Thanks in advance.
Jason FlippenJason Flippen

Hi Mohan SFDC 25,

Once you have the Id of the User you want to add to the Permission Set, you then need to query for the Id of the Permission Set you want to assign them to.  After you have those things, you can use the following code:
PermissionSetAssignment psa = new PermissionSetAssignment();
psa.PermissionSetId = permissionSetId;
psa.AssigneeId = assigneeId;
The permissionSetId variable contains the Id of the Permission Set you are adding the User to, and the assignedId is the Id of the User you are assigning to the Permission Set.

I hope this helps.