0

I want to build the the query to update the object permissions to grant the read edit access of specific profile for the custom object. any idea how to do it

0

I don't think you can update the Profile object using SOQL directly, instead use metadata API to create/update the profile from apex.

0

You can do this with a SOQL update statement:

  1. If the object permissions record exists, in the object permissions table, you should toggle the value on the existing object permissions record.

  2. If the object permissions record does not exist, you should create a new object permissions record.

The ParentId for the object permissions table is the Id from the permissionset table. You can retrieve this by using the following SOQL to get Profiles Only:

SELECT Id, ProfileId, Profile.Name 
FROM PermissionSet
WHERE IsOwnedByProfile = true

Please note that you may not be able to update object permissions on some standard profiles, such as system administrator. If you want to exclude custom profiles (recommended), you can add IsCustom to the above query.

Here is a link to the overview of the ObjectPermissions object and permissions that it extends: https://developer.salesforce.com/docs/atlas.en-us.api.meta/api/sforce_api_objects_objectpermissions.htm

It goes without saying, but if you have a certain use case, since you are updating permissions for a record, please make sure you do appropriate security checks, include with sharing in your code, etc. If you are doing this via dataloader, then the above statement need not apply, as the system would prevent you from inserting/updating a record that you would not be allowed to.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.