You need to sign in to do that
Don't have an account?
ilewi121
I'm trying to prevent multiple SOQL queries in my method by creating a static list outside of the method.
The list is pulling from custom settings, so they should be static when the class runs.
Unfortunately, when I run the test for this class, the debug log shows nothing.
Am I putting this list in the wrong place?
Class
Debug Log
Reference static list in method
I'm trying to prevent multiple SOQL queries in my method by creating a static list outside of the method.
The list is pulling from custom settings, so they should be static when the class runs.
Unfortunately, when I run the test for this class, the debug log shows nothing.
Am I putting this list in the wrong place?
Class
public class modeRanges{ public static List<ModeRange__c> ModeRanges = [SELECT Mode_Type__c, Spend_Picklist_Value__c, Volume_Picklist_Value__c FROM ModeRange__c]; public static void setSpendRangeFromVolumeRange(List<Mode__c> Modes){ System.debug('ModeRanges: ' + ModeRanges); for(Mode__c m :Modes){ for(ModeRange__c r: ModeRanges){ if(m.Type__c == r.Mode_Type__c && m.Est_Volume__c == r.Volume_Picklist_Value__c){ m.Est_Spend__c = r.Spend_Picklist_Value__c; } } } } }
Debug Log
15:45:01:042 USER_DEBUG [12]|DEBUG|ModeRanges: ()
If yes, how many rows is it returning?
My best guess is that your test method setup doesn't create any ModeRanges__c records. Test methods don't have access to custom settings by default. Either add SeeAllData=true to your @isTest annotation, or create some ModeRanges__c settings in the setup of your test.
All Answers
If yes, how many rows is it returning?
My best guess is that your test method setup doesn't create any ModeRanges__c records. Test methods don't have access to custom settings by default. Either add SeeAllData=true to your @isTest annotation, or create some ModeRanges__c settings in the setup of your test.
That said, I tested via UI and it still doesn't work, even though I have all the necessary ModeRanges__c records. When I run my SOQL query in the query editor, it pulls the records, so my methods are not able to access the list in the outer class.
Do you have any ideas how I can access a static list in the outer class from a method within the class?