You need to sign in to do that
Don't have an account?
Roelof Wal
Apex code works, but not during test
I have the following code:
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
On the other hand, the code works correct in the normal situations.
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__cThis looks wrong because it should be
select Name,Sn__c,Rn__c from Custom_items__c where Name in ('thevalue') order by Ordering_number__cSo instead of (thevalue) it should be ('thevalue') to be correct.
On the other hand, the code works correct in the normal situations.
Within test class you need to fill the Opportunity object first since it is not retrieving real data from the system
All Answers
But I was only trying to see with the debug statement what could be wrong and what possible reason there could be for the code to not "fill" myResult.
This is what the Raw log shows:
Whatever I try the result of myResult is always NULL.
Even when I remove the variable from the query and change the whole query to a standard SalesForce object like Account, it always results NULL.
Within test class you need to fill the Opportunity object first since it is not retrieving real data from the system