You need to sign in to do that
Don't have an account?
Kbhaskar
Apex Code to add permissions to Permission Sets
hi,
i'm trying to update permission set from apex code but still it's incorrect can anyone help me out !
Error: actionradioab Compile Error: Variable does not exist: SobjectType at line 40 column 9
i'm trying to update permission set from apex code but still it's incorrect can anyone help me out !
Error: actionradioab Compile Error: Variable does not exist: SobjectType at line 40 column 9
} public pagereference Assign() { if(selectedValue == 'readselected') { //update Object permission for Opportunity actionradioab op = new actionradioab(); op.permissionSetID = parameterValue; op.SobjectType = 'Opportunity'; op.PermissionsCreate = false; op.PermissionsRead = true; op.PermissionsWrite = false; update op; } } }
You can update permission set prividege using code similar to this -
PermissionSet ps =[select id,ProfileId,SystemModstamp,UserLicenseId FROM PermissionSet where name='MyPermission'];
ObjectPermissions op = new ObjectPermissions();
op.parentid = ps.id;
op.SobjectType = 'Opportunity';
op.PermissionsCreate = false;
op.PermissionsRead = true;
op.PermissionsEdit = false;
insert op;
Once you insert a record for a SobjectType, you can query the same record in ObjectPermissions to make firther change.
Hope this will help you.
As a best practice please mark an answer as 'Solved' if it helps you.
Regards,
Shashi
All Answers
You can update permission set prividege using code similar to this -
PermissionSet ps =[select id,ProfileId,SystemModstamp,UserLicenseId FROM PermissionSet where name='MyPermission'];
ObjectPermissions op = new ObjectPermissions();
op.parentid = ps.id;
op.SobjectType = 'Opportunity';
op.PermissionsCreate = false;
op.PermissionsRead = true;
op.PermissionsEdit = false;
insert op;
Once you insert a record for a SobjectType, you can query the same record in ObjectPermissions to make firther change.
Hope this will help you.
As a best practice please mark an answer as 'Solved' if it helps you.
Regards,
Shashi