Loading

B2B Commerce For Visualforce - Resolve Error "Too many SOQL queries: 101" In Custom Test Class

Udgivelsesdato: Aug 26, 2024
Beskrivelse

Unit tests causing many calls to ccrz.cc_CallContext.getConfigValue can fail with Apex Exception "Too many SOQL queries: 101" if mock Config Setting data is not inserted in the test method.

When ccApiTestData.setupData is called, the data is only valid for a single transaction. If the setupData method is called during a @TestSetup method, the in-memory guard we have in place for fetching configurations gets reset and redundant SOQL will be exectued in the IsTest annotated methods for every call to ccrz.cc_CallContext.getConfigValue.

Løsning

1. Ensure ccrz.ccApiTestData.setupData is called in each individual @isTest annotated method.

2. If version < 4.13 (4.139), populate ccrz.CCApiTestData.CONFIG_SETTINGS with data. If no specific data is needed, you will still need to include some mock config setting as part of the invocation to ccApiTestData.setupData.
Map<String, Object> configSettingMock = new Map<String, Object> {
                'safe' => 'default'
            };
ccrz.ccApiTestData.setupData(new Map<String,Map<String,Object>> {
    ccrz.CCApiTestData.CONFIG_SETTINGS => configSettingMock
};

 

Vidensartikelnummer

000395910

 
Indlæser
Salesforce Help | Article