+ Start a Discussion
AltiumForceAltiumForce 

How to find out what pricebooks the current user can use?

Hi,

I am working on an Visualforce page for opportunity object, I need to ask user to select a pricebook for the opportunity.

 

It is straight forward for standard users - just show all active pricebooks, but parter users can only access the pricebooks defined in pricebook sharing.

 

How do I find out what pricebooks the current user can use in Apex code?

 

Thanks,

Ian

   

AltiumForceAltiumForce

I found something in the Apex language reference (Page 93~94):

 

 

Using the with sharing or without sharing Keywords ...... In addition, all SOQL or SOSL queries that use PriceBook2 ignore the with sharing keyword. All PriceBook records are returned, regardless of the applied sharing rules.

 

 

There must be a way.

Standard  Salesforce choosepricebook page can do it (https://emea.salesforce.com/oppitm/choosepricebook.jsp?id=)

 

 

jwolfjwolf
Did you ever find out a way to do this through apex? I need to be able to display the list of pricebooks based on a users' permissions.
AltiumForceAltiumForce

No, I didn't. 

 

I ended up using my own data to determine the pricebook list for the partner users. 

michaelforcemichaelforce

It's been over a year since the last post on this thread... anyone figure out a solution by chance?

sfdcfoxsfdcfox

 

System.Debug([select ID From PricebookShare]);

...

 

 

Compile Error: line 1, column 14: sObject type 'PricebookShare' is not supported.

 

So, no, you can't conveniently determine which pricebooks they have access to use.

 

Using with sharing seems to be the only way it might be supported, but if that fails, there's no other way to get to this information right now. Might need to use a Custom Setting for administrators to allow/disallow certain pricebooks.

fgwarbfgwarb

Slightly different issue.  I need to be able to give partners access to new pricebooks via apex!  But it doesn't look like Pricebook2Share / PricebookShare objects are available via apex/SOQL.