Direct SOQL Return in method causes issues with SOQL

Issue #987 resolved
Vladyslav Petrovych created an issue

The following causes the SOQL query not to be recognised:

    @RemoteAction @ReadOnly
    public static List<Shipment__c> retrieveShipments(Date weekStartDate) {
        return [SELECT Id,Name,Shipment_Date__c,Account__c,Address__c,Volume__c,Driver__c FROM Shipment__c WHERE Shipment_Date__c >= :weekStartDate AND Shipment_Date__c < :weekStartDate.addDays(7)];
    }

while the following works correctly:

    @RemoteAction @ReadOnly
    public static List<Shipment__c> retrieveShipments(Date weekStartDate) {
        List<Shipment__c> result = [SELECT Id,Name,Shipment_Date__c,Account__c,Address__c,Volume__c,Driver__c FROM Shipment__c WHERE Shipment_Date__c >= :weekStartDate AND Shipment_Date__c < :weekStartDate.addDays(7)];
        return result;
    }

Comments (9)

  1. Scott Wells repo owner

    Thanks for logging and for including example code. I'll let you know if I have any trouble reproducing it. Otherwise I'll try to include the fix in a near-term build.

  2. Scott Wells repo owner

    Out of curiosity, do you happen to have more than one SObject in this org named Shipment__c? The example that's failing is showing everything related to that type as unresolvable which makes me think that it's having trouble finding the unique type named Shipment__c.

  3. Vladyslav Petrovych reporter

    Yep, I do have more than one. The other one is in managed package. I'll attach offline symbol table to make it easier to reproduce.

  4. Scott Wells repo owner

    Thanks for confirming. No need to attach the OST unless you want to. I can mock up the scenario pretty quickly, I think. Just good to know the potential contributing factors.

  5. Scott Wells repo owner

    Is this still happening for you? I've tried to reproduce it but haven't been able to do so. Here's the code I've used that doesn't yield any errors:

        @RemoteAction
        @ReadOnly
        public List<Expense__c> testDirectSoqlReturn()
        {
            return [SELECT Id FROM Expense__c];
        }
    

    Please let me know if you are still able to reproduce it on the most recent build and, if so, please provide an example that causes the issue. If it's based on a custom object, please provide a description or shell of the custom object that I can model in my org so that I can try the exact same code. Thanks!

  6. Scott Wells repo owner

    Also, please take a look at #851 where I can reproduce similar behavior by having a local custom object with the same name as a custom object from an installed managed package. If you feel yours is potentially the same issue, please let me know and I'll merge the issues. Hopefully I'll have that one addressed in the next build.

  7. Log in to comment