2

我正在尝试更新 slaesforce 中的 ObjectPermissions 对象,以便配置文件将获得访问类似于其他配置文件的对象的权限。我写了一个代码

我的代码段是

 PermissionSet set1 = [SELECT Id From PermissionSet 
                         WHERE profileId = : SourceProfileId LIMIT 1] ;
 PermissionSet set2 = [SELECT Id FROM PermissionSet 
                         WHERE profileId = : TargetProfileId LIMIT 1];
 List<ObjectPermissions> oo = [SELECT Id,
                                      SObjectType,
                                      ParentId,
                                      PermissionsCreate,
                                      PermissionsDelete,
                                      PermissionsEdit,
                                      PermissionsModifyAllRecords,
                                      PermissionsRead,
                                      PermissionsViewAllRecords 
                                 FROM ObjectPermissions 
                                     WHERE ParentId = : set1.id];


 List<ObjectPermissions> oo1 = [SELECT ParentId,
                                      Id,
                                      SObjectType,
                                      PermissionsCreate,
                                      PermissionsDelete,
                                      PermissionsEdit,
                                      PermissionsModifyAllRecords,
                                      PermissionsRead,
                                      PermissionsViewAllRecords 
                                 FROM ObjectPermissions 
                                     WHERE ParentId = : set2.Id];
 Map<String , ObjectPermissions> source_obj = new Map<String, ObjectPermissions>();
 Map<String , ObjectPermissions> target_obj = new Map<String, ObjectPermissions>();
 for (ObjectPermissions o : oo) {
     source_obj.put(o.SObjectType, o);
 }
 for (ObjectPermissions o : oo1) {
     target_obj.put(o.SObjectType, o);
 }
 ObjectPermissions target, source;
 for (String s : source_obj.keySet() ) {
     if (target_obj.containsKey(s)) {
         target = target_obj.get(s);
         source = source_obj.get(s);
         System.debug('Source is:' + source);
         System.debug('Target is : ' + target);
         target.PermissionsCreate = source.PermissionsCreate;
         target.PermissionsDelete = source.PermissionsDelete;
         target.PermissionsEdit = source.PermissionsEdit;
         target.PermissionsModifyAllRecords = source.PermissionsModifyAllRecords;
         target.PermissionsRead = source.PermissionsRead;
         target.PermissionsViewAllRecords = source.PermissionsViewAllRecords;
         update target;
     } else {
         target = new ObjectPermissions(SObjectType = s );
         source = source_obj.get(s);
         target.PermissionsCreate = source.PermissionsCreate;
         target.PermissionsDelete = source.PermissionsDelete;
         target.PermissionsEdit = source.PermissionsEdit;
         target.PermissionsModifyAllRecords = source.PermissionsModifyAllRecords;
         target.PermissionsRead = source.PermissionsRead;
         target.PermissionsViewAllRecords = source.PermissionsViewAllRecords;
         insert target;
     }
 }

当控制来到这条线

更新目标;它给出了错误

更新失败。第 0 行的第一个异常,ID 为 110i0000007KNEvAAO;第一个错误:INVALID_CROSS_REFERENCE_KEY,您不能为此权限集父级创建、编辑或删除记录,因为它与简档相关联。父 ID:0PSi00000009BE9:[]

我无法弄清楚为什么我会遇到此错误,请有人帮助解决此错误

4

1 回答 1

2

您尝试更新的权限集已经与您的一些 id=0PSi00000009BE9 ​​的个人资料相关联 转到

https://ap1.salesforce.com/0PSi00000009BE9​​并在那里检查。

于 2013-07-24T18:01:28.377 回答