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
mounika darisi 6mounika darisi 6 

Permissionsets through apex code

Hi all,

I am trying to create Permissionsets from apex.I am able to create  permission sets with object and field permissions enabled through apex. Any Idea how to create permissionsets with specific tab settings permissions enabled through apex code ?
Below is how I gave object and field permissions.

PermissionSet ps = new PermissionSet();
    ps.Name = 'Test';
    ps.Label = 'Test';
insert ps;
ObjectPermissions op = new ObjectPermissions();
op.parentId = ps.Id;
op.SobjectType = 'Account';
op.PermissionsCreate = true;
op.PermissionsRead = true;
insert op;
FieldPermissions fp = new FieldPermissions();
fp.parentId = ps.Id;
fp.SobjectType = 'Account';
fp.Field = 'Account.AccountSource';
fp.PermissionsRead = true;
fp.PermissionsEdit = true;
insert fp;


 

NagaNaga (Salesforce Developers) 
Hi Mounika,

Please let me know if this code works:

PermissionSetAssignment psa = new PermissionSetAssignment(PermissionSetId = myPermissionSetId, AssigneeId = myAssigneeId); insert psa;

Best Regards
Naga Kiran
 
mounika darisi 6mounika darisi 6

Hi Naga Kiran,

Thanks, but I am searching for something by which I can enable tab access to permissionset which I want to insert.

SFDC HedgehogSFDC Hedgehog
Hi Mounika

I found this - hope it helps
http://salesforce.stackexchange.com/questions/44176/tab-settings-not-available-on-permission-set