+ Start a Discussion

No access to products but use pricebook

I have a situation wherein I want to hide products from users but still let them use pricebooks (through apex).
I have a trigger to assign default pricebook to opportunity. But I get an insufficient priviledges error, which is I think because I have take away access to prdoucts (which takes away access to pricebooks).

Does anybody have suggestion to take away access on products but still let users use pricebooks?

Any reason to not just remove the Products tab and make that not visible.  Then still leave object level available?  Or, you could have your trigger call a class that has with sharing [1] and then have that class do your pricebook related things.  With sharing will cause it to run "as an admin" which will have access to it.

Not 100% sure the sharing thing will work, but it's worth a shot if just removing the Product tab isn't enough.

[1] https://developer.salesforce.com/docs/atlas.en-us.apexcode.meta/apexcode/apex_classes_keywords_sharing.htm
Thank you for the suggestion. The reason why hiding Products tab won't work is that, through global search the users can still see all the products. So, we want to take aways complete access from user.

I will try out your suggestion about calling a class from trigger. Though I was under impression that triggers always run in admin context.
No, triggers run in the context of the user that initiated the request.