Skip to main content

I have the following code:

public with sharing class getCustomvalues {

        public final Account account;

        public List<String> myitems {get; set;}

        public List<Custom_items__c> myResult {get;set;}

    

        public getCustomvalues() {

            Id id = ApexPages.currentPage().getParameters().get('id');

            account =  [SELECT Account.Name, items__c FROM Account WHERE Id = :id];

            myitems = new List<String>();

            if (account.items__c== null) {

                 myResult =null;  

                //System.debug(LoggingLevel.ERROR, 'result will be empty');

            } else {

                myitems.addAll(account.items__c.split(';'));

System.debug('myResult Query=select Name,Sn__c,Rn__c from Custom_items__c where Name in '+myitems+' order by Ordering_number__c');

                   myResult =[select Name,Sn__c,Rn__c from Custom_items__c where Name in :myitems order by Ordering_number__c];

            }

        }

        public Account getAccount() {

        

            return account;

        }

}

I wrote a test class that works good, but for some reason the myResult object stays empty.

Looking at the test logs I see that  (account.items__c== null) { is not true during the test, so it goes to the } else { section and there myitems is filled and contains data. 

One thing I noticed was that the debug log showed the following for the query

select Name,Sn__c,Rn__c from Custom_items__c where Name in (thevalue) order by Ordering_number__c

This looks wrong because it should be

select Name,Sn__c,Rn__c from Custom_items__c where Name in ('thevalue') order by Ordering_number__c

So instead of (thevalue) it should be ('thevalue') to be correct. 

On the other hand, the code works correct in the normal situations. 

 
4 个回答
  1. 2022年7月25日 09:52
    aha....

    Within test class you need to fill the Opportunity object first since it is not retrieving real data from the system 
0/9000