apex – For a particular Perm Set, how to write a SOQL to query “Read Access” for all Fields (FLS) for an Object

You can’t query for records that don’t exist. If PermissionsRead is false for a given field, that record won’t exist. This is a performance optimization. Instead, you’ll want to iterate over each object, describe the fields for the object, query the FieldPermissions object to see which fields already have permission, then attempt to create a list of field permissions that don’t exist. Finally, remember to use Database.insert(records, false);, because some fields can’t have their permissions modified. We could try to codify all the rules manually, but it’s easier to just let the database do it for us. You can also use ObjectPermissions to restrict the FieldPermissions query to just objects that are being granted permission.

Read more here: Source link