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
aam1raam1r 

Query works in one class but not the other

I have two clases:
1. a controller class to a vf page and another as
2. a helper class accessed by multple classes. 

I have a simple query running in the helper class that is failing to return any records:
...
public static void refreshOrder(Id orderId, Id accountId){

        // Retrieve the Order
        Order ord = [Select Id, Name, Status From Order Where Id = :orderId];

...
The controller class that calls the above method has the following extract:
...

Order order = new Order(
    Pricebook2Id = OrderHelper.getStandardPriceBookId(),
    Status = ORDER_STATUS_PENDING_PAYMENT, 
    AccountId = acc.Id
    EffectiveDate = System.today(),
    CurrencyIsoCode=pkgCurrencyCode
 );
        
 insert order;

OrderHelper.refreshOrder(order.Id, acc.Id);
...
Any idea why a system.debug in the helper class does show a valid Order Id being apssed but then the simple order query does not return anything, and instead throws an error:
"List has no rows for assignment to SObject" ?
 
Best Answer chosen by aam1r
aam1raam1r
Ok, i figured thsi out.  i thought i'd post in case anyone else faces the same issue.  Here's what i checked:
1. User permissions.  This was part of a process involving a Site Guest User.  And although i had set up sharing rules i guess this user worjks a bit differently from a standard, rather a normal user in salesforce
2. I moved the select query from the helper class to teh controller class and then passed the field values to the helper class - and it did work.  So user has access, but only in one class - not the other.
3. I then checked the class definition and yes, it was set to public with sharing. So,
4. i changed this to public without sharing

And it all worked.  Of course, this means that sharing settings will not apply in this class, and that it will run on a system level.  But that's fine.  I'll control access to sensative info via the profile when needed.
Thanks for looking!