Logger test hardcodes value for custom field and tests are failing
Package Edition of Nebula Logger
Unlocked Package
Package Version of Nebula Logger
v4.16.5
New Bug Summary
We are using Nebula for logging of errors in a Salesforce org. We added a field to Log_Entry__c object and updated event and the mapping in custom metadata. However we use a Nebula package in scratch orgs together with other custom packages and we run all tests. I reproduced the same test failure in my scratch org where I have Nebula installed, I ran all tests in the org. We were getting this error:
Class.LogEntryEventHandler_Tests.it_should_not_create_log_entry_data_when_platform_event_storage_logging_level_is_not_met: line 88, column 1 LogEntryEventHandler_Tests.it_should_not_normalize_scenario_data_when_data_normalization_is_disabled Fail System.DmlException: Upsert failed. First exception on row 0; first error: INVALID_OR_NULL_FOR_RESTRICTED_PICKLIST, Process Name: bad value for restricted picklist field: ProcessName__c Test STRING: [ProcessName__c] Class.LoggerDataStore.Database.upsertRecords: line 276, column 1 Class.LogEntryEventHandler.upsertLogEntries: line 410, column 1 Class.LogEntryEventHandler.executeAfterInsert: line 60, column 1 Class.LoggerSObjectHandler.execute: line 125, column 1 Class.LoggerMockDataStore.MockEventBus.deliver: line 157, column 1
After troubleshooting and searching in Salesforce and in Nebula repository I discovered it is in this class - see the line 896, it hardcodes the string field value to be [Name of the custom field ] Test STRING. In our case we use a global value set which is a restricted picklist by default so the test is failing. Our field is a picklist value, not string but still it works as String. I haven´t found this value hardcoded anywhere else in the code in the repository:
The custom field is ProcessName__c/Process Name. We were guessing and are added various values to the global set, finally this was the correct combination, then the tests passed:
<customValue>
<fullName>ProcessName__c Test STRING</fullName>
<default>false</default>
<label>ProcessName__c Test STRING</label>
</customValue>
<customValue>
<fullName>Process Name Test STRING</fullName>
<default>false</default>
<label>Process Name Test STRING</label>
</customValue>
Our field metadata:
<?xml version="1.0" encoding="UTF-8"?>
<CustomField xmlns="[http://soap.sforce.com/2006/04/metadata](https://url.uk.m.mimecastprotect.com/s/-v0SCyr4XtXBj7N5iZfZCxqI2t?domain=soap.sforce.com)">
<fullName>ProcessName__c</fullName>
<label>Process Name</label>
<required>false</required>
<trackTrending>false</trackTrending>
<type>Picklist</type>
<valueSet>
<restricted>true</restricted>
<valueSetName>Process_Names</valueSetName>
</valueSet>
</CustomField>
Hi @mbrezina , thanks for reporting this! I hadn't thought of this use case of using a mapping to a restricted picklist field. Luckily, I already have a change (intended to fix a slightly different issue) that should resolve this - I don't know when exactly I'll be able to publish a release, but this should hopefully be fixed in the next release or two.