Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

LoggerSettings creation fails as part of a wire function call #205

Closed
arbokrad opened this issue Sep 16, 2021 · 3 comments · Fixed by #191
Closed

LoggerSettings creation fails as part of a wire function call #205

arbokrad opened this issue Sep 16, 2021 · 3 comments · Fixed by #191
Labels
Layer: Configuration Items related to the custom hierarchy setting LoggerSettings__c or any included custom metadata type Layer: Logger Engine Items related to the core logging engine Package Type: Unlocked Package Issues and enhancements that specifically apply to the unlocked package Type: Bug Something isn't working

Comments

@arbokrad
Copy link

arbokrad commented Sep 16, 2021

When we installed the unlocked version of Nebula, we ran into an error with the following logs:

14:46:47.0 (10466217)|DML_BEGIN|[2645]|Op:Insert|Type:LoggerSettings__c|Rows:1
14:46:47.0 (10580196)|EXCEPTION_THROWN|[2645]|System.LimitException: Too many DML statements: 1
14:46:47.0 (10880657)|SYSTEM_MODE_EXIT|false
14:46:47.0 (10997450)|SYSTEM_MODE_EXIT|true
14:46:47.0 (11127246)|FATAL_ERROR|System.LimitException: Too many DML statements: 1

Class.Logger.setupOrgDefaults: line 2645, column 1
Class.Logger: line 47, column 1
Class.LWC_CaseHighlights.getCaseDetails: line 18, column 1
14:46:47.0 (11178717)|FATAL_ERROR|System.LimitException: Too many DML statements: 1

Class.Logger.setupOrgDefaults: line 2645, column 1
Class.Logger: line 47, column 1
Class.LWC_CaseHighlights.getCaseDetails: line 18, column 1
14:46:47.11 (11198328)|CUMULATIVE_LIMIT_USAGE
14:46:47.11 (11198328)|LIMIT_USAGE_FOR_NS|(default)|
  Number of SOQL queries: 0 out of 100
  Number of query rows: 0 out of 50000
  Number of SOSL queries: 0 out of 20
  Number of DML statements: 1 out of 0 ******* CLOSE TO LIMIT
  Number of Publish Immediate DML: 0 out of 150
  Number of DML rows: 0 out of 10000
  Maximum CPU time: 0 out of 10000
  Maximum heap size: 0 out of 6000000
  Number of callouts: 0 out of 100
  Number of Email Invocations: 0 out of 10
  Number of future calls: 0 out of 50
  Number of queueable jobs added to the queue: 0 out of 50
  Number of Mobile Apex push calls: 0 out of 10

This trace of this error is happening as part of a @wire function call:

    @AuraEnabled(Cacheable=true)
    public static DTO_CaseHighlightsResponse getCaseDetails( Id caseId, List<String> fieldPaths ) {
        final String METHOD_NAME = 'getCaseDetails()';
        Logger.debug( new LogMessage( LoggerConstants.METHOD_LOG_UNFORMATTED, CLASS_NAME, METHOD_NAME, LoggerConstants.IM_HERE ));

        try {
            // snip
        }
        finally {
            Logger.saveLog();
        }
    }

It appears that this is related to certain contexts not being able to do DML (e.g. create the initial LoggerSettings, if none exists)

https://www.levelupsalesforce.com/lwc-too-many-dml-statements-1

Creating the LoggerSettings__c entry (org defaults in our case) immediately stops this failure.

@jongpie
Copy link
Owner

jongpie commented Sep 16, 2021

Thanks for reporting this! I'll plan to fix this in my open PR #191 (which will be release v4.6.8). Let me know if you run into any other issues!

@jongpie jongpie added Type: Bug Something isn't working Layer: Logger Engine Items related to the core logging engine Layer: Configuration Items related to the custom hierarchy setting LoggerSettings__c or any included custom metadata type Package Type: Unlocked Package Issues and enhancements that specifically apply to the unlocked package labels Sep 16, 2021
jongpie added a commit that referenced this issue Sep 16, 2021
@jongpie
Copy link
Owner

jongpie commented Sep 16, 2021

@arbokrad I was able to fix this as part of PR #191 by making 2 (fairly small) changes

  • I've removed the DML entirely for LoggerSettings__c - this is at least the third time that it's caused issues for someone, so I think it's not the best approach to have DML automatically happen
  • I've improved how the in-memory version of LoggerSettings__c is initialized in Logger.getUserSettings() so that it correctly loads all of the fields' default values

With these 2 changes, if an org does not have LoggerSettings__c configured, then Logger will still function - it will just use the default field values for each of the fields on LoggerSettings__c.

jongpie added a commit that referenced this issue Sep 16, 2021
jongpie added a commit that referenced this issue Sep 22, 2021
* Created new lwc logEntryEventStream for streaming LogEntryEvent__e

* Added new tab to perm sets

* Added stream section to README

* Created new package version 4.6.8

* Fixed #204 - Improved approach for querying for an Apex class in `LogEntryHandler_Tests` to handle orgs that have 2 `Logger` classes (one with namespace and another without namespace)

* Fixed #205 - Eliminated DML on LoggerSettings__c, improved in-memory creation of defaults

* Fixed some issues reported by lint

* Add husky pre-commit setup, fixed some tests

* Added package-lock.json to repo

* Added npm caching in deploy.yml

* Added step to auto-delete unvalidated package version ID

* Added husky pre-commit hook, using lint-staged

* Removed install step for sfdx-scanner and using npm version instead

* Cleaned up ordering of sections in package.json

* Added GitHub issue templates to the repo

* Updated npm scripts "lint" and "prettier" to "lint:fix" and "prettier:fix" for clarity

* Changed a few lint rules to 'warn' instead of 'off'
@jongpie
Copy link
Owner

jongpie commented Sep 22, 2021

@arbokrad I've just release a new version of the unlocked package, v4.6.8, which includes a fix for this. Thanks again for reporting this issue!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Layer: Configuration Items related to the custom hierarchy setting LoggerSettings__c or any included custom metadata type Layer: Logger Engine Items related to the core logging engine Package Type: Unlocked Package Issues and enhancements that specifically apply to the unlocked package Type: Bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants