需求:Release的时候,要把字段的权限设置到生产环境,但一个一个字段分别设置效率太低,效率高的方法来了
一般我们设置字段的权限,需要打开Profile,或者PermissionSet来设置具体的字段。
有没有更有效率的方法呢?
有的。
使用下面的SOQL,把Sandbox环境上面的权限设置用DataLoader导出来,然后导入到生产环境上面就可以了
这个是Object的权限
SELECT Id, Parent.Profile.Name, SobjectType, PermissionsCreate, PermissionsDelete, PermissionsEdit, PermissionsModifyAllRecords, PermissionsRead, PermissionsViewAllRecords FROM ObjectPermissions where Parent.Profile.Name='System Administrator' and SobjectType='Study__c'
_ | Id | Parent | Parent.Profile | Parent.Profile.Name | SobjectType | PermissionsCreate | PermissionsDelete | PermissionsEdit | PermissionsModifyAllRecords | PermissionsRead | PermissionsViewAllRecords |
ObjectPermissions | 00000004oYSra00AQB | PermissionSet | Profile | System Administrator | Study__c | true | true | true | true | true | true |
这个是字段的权限
我们要把Profile里面关于字段的权限的设置通过SOQL给取出来。
这个SOQL,就能够把Profile里面关于字段的权限的设置给取出来。
SELECT Id, Field, SObjectType, PermissionsRead, PermissionsEdit
FROM fieldPermissions
WHERE SObjectType = 'Study__c'
AND parentId in ( SELECT id
FROM permissionSet
WHERE PermissionSet.Profile.Name = 'Contract Manager')
取出来的结果如下
"_" "Id" "Field" "SobjectType" "PermissionsRead" "PermissionsEdit"
"[FieldPermissions]" "01k5h0000QeGvMCAQ0" "Study__c.Memo__c" "Study__c" "true" "true"
"[FieldPermissions]" "01k5h0000vvaYlQAAU" "Study__c.Certification__c" "Study__c" "true" "true"
"[FieldPermissions]" "01k5h0000vvc6c4AAA" "Study__c.CloseDate__c" "Study__c" "true" "true"
"[FieldPermissions]" "01k5h0000w0EYUOAA4" "Study__c.Year__c" "Study__c" "true" "true"
"[FieldPermissions]" "01k5h0000w0EYUyAAO" "Study__c.Month__c" "Study__c" "true" "true"
"[FieldPermissions]" "01k5h0000w0EYVYAA4" "Study__c.SalesTargetAmount_Direct__c" "Study__c" "true" "true"
"[FieldPermissions]" "01k5h0000w0EYW8AAO" "Study__c.SalesByYear_BD_parent__c" "Study__c" "true" "true"
"[FieldPermissions]" "01k5h0000w0FdBgAAK" "Study__c.MyEmail__c" "Study__c" "true" "true"
参考文章链接
参考到了下面的文章
Update custom Profile and Permission Set object level permissions with Data Loader
https://help.salesforce.com/s/articleView?id=000381102&type=1