1

My org is running some apex code that pulls objects and passes them to a mobile app. The apex code in question is designed to be run as the sales rep that is logged in via the app. For some reason when I query for the pricebook and pricebookentry objects it seems the apex flips into god-mode and pulls all of the PBs and PBEs, even though there is only one pricebook shared with a certain user.

Are there specific settings that will make the PBs and PBEs adhere to sharing rules when querying via Apex?

APEX:

String query = constructQuery(ce, lastModifiedDate, offsetId, True);    

Query returned from constructQuery(): SELECT Id,  CurrencyIsoCode, LastModifiedDate FROM Pricebook2 WHERE (IsActive=true)  ORDER BY Id DESC LIMIT 5000

List<SObject> objs = Database.query(query);
if (objs != null && objs.size() > 0) {
    response.records.addAll(objs);
}

This is a known issue apparently. Follow below link (last warning box at the bottom of the page): http://www.salesforce.com/us/developer/docs/apexcode/index_Left.htm#StartTopic=Content/apex_security_sharing_rules.htm?SearchType=Stem

3
  • 1
    Welcome to SF.SE Scott H. Without seeing the Apex code you're running that you've mentioned, its difficult for any of us to respond to your question. Please post your code if you'd like a useful response. Does your code use "With Sharing" keywords?
    – crmprogdev
    Commented Dec 22, 2014 at 16:57
  • Hey crmprogdev, I am working on generalizing the code now and will post shortly. We are using "with sharing".
    – Scott H
    Commented Dec 22, 2014 at 17:07
  • This answer might help anyone who stumbles upon this Commented Oct 27, 2015 at 20:08

1 Answer 1

2

This is a known issue apparently. Follow below link (last warning box at the bottom of the page): http://www.salesforce.com/us/developer/docs/apexcode/index_Left.htm#StartTopic=Content/apex_security_sharing_rules.htm?SearchType=Stem

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .