function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
fgwarb_devfgwarb_dev 

Query User CRUD

I have a class which is not using the with sharing modifier.

 

I need to ensure that people aren't enabled to delete opportunities they shouldn't.

 

All of the people who aren't supposed to delete opportunities share a profile, and the Delete CRUD setting is switched off.

 

 

How do I query the CRUD to determine if the current user is enabled to delete an Opportunity?

 

I know about how to determine current context access to deletion:

 

if(!Opportunity.sObjectType.getDescribe().isDeletable()){
 //current context does not permit opportunity deletion.
}

 

 

but since we aren't using the with sharing modifier, this won't work.... Help?

 

Shoby Abdi.ax910Shoby Abdi.ax910

If you don't use with sharing you won't be able to check CRUD permissions on records and sObjects. The closest check you can make is to check if the current User has that specific profile or checking if the profile has 

p.PermissionsModifyAllData. 

 

Why can't you use with sharing? What about calling out to a separate class with sharing enabled and doing the check you described in a static method returning a Boolean whether they're allowed or not. 

fgwarb_devfgwarb_dev

:smileysad:

 

Here's hoping that sometime in the future SF will enable CRUD querying.

 

I didn't write the class, and I'm sure that adding with sharing would cause problems for our users in other countries.

 

Having a way to derive CRUD based upon UserId would have enabled me to seamlessly and definitively drop in our region specific requirements.   

 

Thanks for the response!  I've submitted an Idea on the feature in the hopes that they'll merge it with an existing one.  https://sites.secure.force.com/success/ideaView?c=09a30000000D9xtAAC&id=08730000000Kk5wAAC