+ Start a Discussion

Possible Apex platform bug?

Hello all:


I found, and worked around, an odd behavior. In a nutshell, I created a StandardSetController based on a QueryLocator. When the QueryLocator's underlying query returns zero records, attempting to set the controller's page set size causes an ugly exception. Worse, this happens in production, but not in my Enterprise sandbox.


Here's the original code:


con = new ApexPages.StandardSetController(Database.getQueryLocator(this.getQuery() ) );


The query is specified by user input via a VisualForce page. When they specify a query that returns no results, then, again in Production, the following exception occurs:


(This is the styled VF error from my page).


I have verified that it's specifically the second line of code that causes the crash.


The above query looks like a query that underlies one of the reports elsewhere in the system.


I fixed this by commenting out the offending line and leaving the set size as the default, which works fine. But why would this happen, and why only in production? Should I be reporting this as a possible platform bug?


Hi, just looking at it visually, I'm wondering if, due to the bad query, this line:

con = new ApexPages.StandardSetController(Database.getQueryLocator(this.getQuery() ) );

threw an exception because there is no StandardSetController constructor for a malformed query error.    (no Scientific notation supported)
However perhaps it caught it and returned con as null and when you try to dereference it in the next line:


You'd get a dereference a null pointer exception???
Perhaps not, but what do you get if you try:

try {
     String q = this.getQuery();
      ApexPages.StandardSetController setControl = null;
       Database.QueryLocator QL = Database.getQueryLocator(q);
     if (QL.getQuery() == q) {  // verify the query that the Locator was initiated with matches the one we gave it.
          setControl = new ApexPages.StandardSetController (QL);
      } else {
            system.debug('You have a bad query: ' + q);
} catch (Exception e) {
    system.debug('Exception: You have a bad query or something else: ' + e);

if (setControl != null) {
     // proceed

Best, Steve.

The description of the error suggests that 1.0E7 is an invalid value (I don't think SOQL supports scientific notation). Make sure you're not somehow accidentially using scientific notation in a dynamic query.

I didn't make this clear, but the "malformed query" that's being reported has NOTHING WHATEVER to do with the query the QueryLocator is actually using! They could not be less related. The "bad query" looks superficially like queries that would be used in some reports I've defined elsewhere using the basic SFDC report building tools. But I know, or am pretty sure I know, that the QueryLocator query is totally unlike the thing in the error message. Only when the QueryLocator query fails do I get this message, and a fragment of this utterly unrelated query!


Regardless, I like the earlier poster's idea of double checking the query a bit. But what's odd is why this totally unrelated query is being referenced.

To reply directly to Steve Bower's post, Steve I will certainly follow this suggestion since it represents a much more "defensive" style of programming and if there's trouble along the way it'll be easier to spot where. Thanks for taking the time to spell that out in detail.

//This is the test class below.....i m nt getting where is problem in the test code but it throws this exception when a case is inserted...

//Standard controller is Case and UsabilityAuditPageController is its extension

// I have problem facing that when i run this test class it gives me error "null pointer exception at

// Class.UsabilityAuditPageControllerTest.myUnitTest: line 99, column 49 External entry point
// Controller name is UsabilityAuditPageController and functions are of void return type
// Page name is UsabilityAuditViewPage
// Any info on this will be appreciated


public  class UsabilityAuditPageControllerTest
    public static testMethod void myUnitTest()
        // TO DO: implement unit test
       RecordType[] rect = [Select Id, Name from RecordType where ((SObjectType = 'Account' AND Name='Customer Account - Professional')
                                                                OR (SObjectType = 'Case' AND Name='Audio'))
                                                                AND isActive= true];
       Map<String,String> mapofrectype= new Map<String,String>();
            for(RecordType rectype : rect)
                mapofrectype.put(rectype.Name, rectype.Id  );
       System.debug('The Value for  RECORDtypeId is--------'+ mapofrectype.get('Audio'));
        String s='this is string' ;
       Account acct = new Account(Name = 'Test2', Sales_Geo__c = 'APAC',
                                RecordTypeId= mapofrectype.get('Customer Account - Professional'),
                                Account_Sub_Type__c = 'Named' , Phone= '987654-3210',
                                Market_Segemnt__c = 'Media Enterprises'
        insert acct;
        Contact cont = new Contact(AccountId = acct.Id,
                                Email = 'sameer@avid.com', Phone= '987654-3210', FirstName ='Ian',
                                LastName= 'Bishop' );
        insert cont;
        Case testAuditPageCase = new Case(Status = 'Open',
                                 AccountId = acct.Id, ContactId= cont.Id,
                              Handled_Out_Of_Business_Hours__c = false, 
                                RecordTypeId= mapofrectype.get('Audio'),Record_Type__c = rect[0].Name);
        insert testAuditPageCase;
        System.debug('The Value for case recordtypeId is----//////////----'+ testAuditPageCase.RecordTypeId);
        System.debug('The Value for CASE recordtypename is---//////////-----'+ testAuditPageCase.Record_Type__c);
        //testAuditPageCase.Status = 'New';
       // update testAuditPageCase;
           /*   INET_Solution__c kbsol= new INET_Solution__c(KB_ID__c = '', Type__c ='Pending');
            insert kbsol;
           INET_CaseCcilSolution__c kbSolutions = new INET_CaseCcilSolution__c(Name ='XYZsolution', Case__c= testAuditPageCase.Id,
                                                                             KB_Solution__c = kbsol.KB_ID__c);
           insert kbsolutions;

           RMA_Message__c rmaMessages= new RMA_Message__c( RMA__c= ,Message_Subject__c = 'Completed');
           insert rmaMessages;  */
          /*CaseHistory[] casehist = [Select Id, CreatedDate, Field, NewValue, OldValue, CreatedById, CreatedBy.Name
                                 From CaseHistory where CaseId =: testAuditPageCase.Id];
          /*    Case_Response__c caseresp = new Case_Response__c(Case__c = testAuditPageCase.Id);
          insert caseresp;*/
          Escalation_response__c escresp = new Escalation_response__c(Case__c = testAuditPageCase.Id, Technical_report__c = 'bad',
                                                                        Support_region__c = 'EMEA',
                                                                        Escalation_Type__c= 'Level 1 Escalation',
                                                                        Escalation_Severity__c='HECC 2nd Level');
          insert escresp;
         /* Survey__c surv = new Survey__c(Case__c = testAuditPageCase.Id, Average_Score__c= 0.00 ,Question_3__c= 'Why??',Question_2__c='What??',Question_1__c ='When??');
          insert surv;
         /*  Attachment attach = new Attachment(ParentId = testAuditPageCase.Id, Description = 'New File');
          insert attach;*/
         //System.currentPageReference().getParameters().put('caseId', testAuditPageCase.Id);*/ 
         PageReference pageRef = Page.UsabilityAuditViewPage;
         System.currentPageReference().getParameters().put('caseId', testAuditPageCase.Id);
            System.debug('The Value for case Id is-->>>>>>>>>>>------'+ testAuditPageCase.Id);
            Case cs= [Select Id from Case where id =: testAuditPageCase.Id];
            System.debug('The Value for CASE ID controller is-----$$$$$$$$$$$$$$---'+ cs);
         ApexPages.StandardController apCntrl = new ApexPages.StandardController(testAuditPageCase);
         System.debug('The Value for controller is--------'+ apCntrl);
         System.debug('The Value for page controller is----********----'+ testAuditPageCase);
        UsabilityAuditPageController usabAudit= new UsabilityAuditPageController(apCntrl);//Controller constructor...this is the line where i get null pointer exception
        System.debug('The value for usabAudit will be...........'+ usabAudit);
        System.debug('The Value for case Id is--------'+ testAuditPageCase.Id);
      //  UsabilityAuditPageController.CaseChild[] caschilds = usabAudit.loadCaseChilds();
    //  UsabilityAuditPageController.customCheckBox;