6

I am trying to create a permission set in my code but I'm getting some issues when I tried to assign an Idea, Product2 or Pricebook. With some other objects like custom or other Standards, I'm able to do it without any issue.

What is it wrong?

PermissionSet ps = new PermissionSet();
ps.Name='TestPermissionSet';
ps.label='TestPermissionSet';
insert ps;

//insert Object permission for Idea
ObjectPermissions op = new ObjectPermissions();
op.parentId = ps.Id;
op.SobjectType = 'Idea';
op.PermissionsCreate = true;
op.PermissionsRead = true;
insert op;

The error that I'm getting is

System.DMLException: Insert failed. 
First exception on row 0; first error: FIELD_INTEGRITY_EXCEPTION, 
The following permission isn't allowed: Read All Idea: []

Thanks

2
  • Odd. I got the same error when trying from anonymous Apex against Product2 but was able to create the ObjectPermissions via the UI with /0PS700000000001/e?s=EntityPermissions&o=Product2. Can you create them via the GUI for Ideas? Dec 19, 2013 at 20:36
  • Yes, if I try via UI, there is no issue and I'm able to create whatever I need. I only get the error if I do it via Console or anonymous. Dec 20, 2013 at 8:53

1 Answer 1

3

Agustina, thank you for posting. I am on the Admin team at salesforce.com and have been able to reproduce this particular issue. You should be able to perform the action you are attempting, but our API validation logic, in this scenario, is slightly too aggressive. I have logged a work item and this will be fixed in an upcoming release.

However, as a work-around, you can use the Metadata API to update the CRUD values on one or multiple permission sets. (keep ViewAll and ModifyAll set to False)

<?xml version="1.0" encoding="UTF-8"?>
<PermissionSet xmlns="http://soap.sforce.com/2006/04/metadata">
    <label>TestPermissionSet</label>
    <objectPermissions>
        <allowCreate>true</allowCreate>
        <allowDelete>false</allowDelete>
        <allowEdit>false</allowEdit>
        <allowRead>true</allowRead>
        <modifyAllRecords>false</modifyAllRecords>
        <object>Idea</object>
        <viewAllRecords>false</viewAllRecords>
    </objectPermissions>
    .
    .
    .
</PermissionSet>

Thank you again for posting and bringing this to our attention.

John

3
  • Thank you very much for the quick reply. Really appreciate it Dec 20, 2013 at 23:04
  • Having same problem with v29.0, will try the metadata api as a workaround. Look forward to fix. Thanks
    – Doug Ayers
    Feb 6, 2014 at 4:35
  • The issue should be resolved with the release of Summer '14 (see trust.salesforce.com for the release schedule).
    – John Brock
    Jul 10, 2014 at 5:54

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .