1
votes

SOQL query not returning rows on visualforce page that do exist in object I am having issues retrieving records which exist from an object via a SOQL query on a visualforce page

How do I know they exist? I have used force explorer and workbench and the following returns a record

SELECT Code__c FROM External_membership_label__c WHERE Code__c = '3'

OK, so the visualforce page does not return the record above, with the code below (few lines from code)

  public String gvlLCCODE {get;set;}

  if(gvlLCCODE != null || gvlLCCODE != ''){

        List<External_membership_label__c> exisitingGVLcodes = [SELECT Code__c FROM External_membership_label__c WHERE Code__c = :gvlLCCODE];

        if (exisitingGVLcodes.Size() > 0){
            //blahh blahh
        }
}

Any suggestions? I have debug telling me 'gvlLCCODE' has a value that exists in the object. Also, if I change the SOQL to say, for example, return the current user from the users table, it returns a record and then enters the IF statement.

I think its a security issue I have missed. But I have also checked these.

Thank you

2

2 Answers

0
votes

well, for one, in your IF statement you probably want to use &&, instead of ||.

Are you having the problem with the test method? if so, then it's because that method doesn't have access to the existing records by default.

0
votes

First of all you should listen to Kirill about the &&, both condtions should be met, not just one. Likewise, the || is meaningless, formula (a!=b)|(a!=c) is always true for any a when b!=c as is the case here

Second, it sounds as you definitely have a security issue here. To verify change extension's declaration from with sharing to without sharing and run. If you get the row you have sharing security issues with the row.