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

Add the ability to set custom fields once per transaction/on every LogEntryEvent__e record #769

Closed
jongpie opened this issue Sep 20, 2024 · 1 comment · Fixed by #772
Closed
Assignees
Labels
Feature: Custom Field Mappings Items related to custom field mappings functionality Layer: Log Management Items related to the custom objects & Logger Console app Layer: Logger Engine Items related to the core logging engine Logging Source: Apex Items related to using Logger within Apex Type: Bug Something isn't working Type: Enhancement New feature or request

Comments

@jongpie
Copy link
Owner

jongpie commented Sep 20, 2024

This idea came up today on SFXD with @surajp. In release v4.13.14, a new instance method was added - LogEntryEventBuilder.setField() - to set custom fields on LogEntryEvent__e:

  • This is useful for fields that are entry-specific (i.e., the field ultimately is mapped to a custom field on LogEntry__c)
  • This is... confusing for fields that are transaction specific (i.e., the field value ultimately is mapped to a custom field on Log__c).
    • Right now, setting the custom field on every entry would probably be the best way to ensure the Log__c field is correctly populated. But doing it on every entry in a transaction is very tedious / not a great developer experience

Ideally, developers should only have to set the transaction-level fields once per transaction. This should be handled with 2 changes:

  1. New static method Logger.setField(SObjectField field, Object value): This will give Apex developers a method that can be called once per transaction for a field, and all generated LogEntryEvent__e records will have it set
  2. Improve Log__c mappings in LogEntryEventHandler: Right now, the trigger handler creates a Log__c record the first time it finds a LogEntryEvent__e record with a specific transaction ID - and then skips the log-related code for any subsequent events with the same transaction ID. In some situations, some Log__c data could be loss, so I'd like to improve how it works
    • If event A has SomeLogField__c = null, and event B has SomeLogField__c = 'some value', then the generated Log__c could have a null value, if both events are published/processed in the same async transaction
@jongpie jongpie added Type: Bug Something isn't working Type: Enhancement New feature or request Logging Source: Apex Items related to using Logger within Apex Layer: Logger Engine Items related to the core logging engine Feature: Custom Field Mappings Items related to custom field mappings functionality labels Sep 20, 2024
@jongpie jongpie self-assigned this Sep 20, 2024
@jongpie jongpie added the Layer: Log Management Items related to the custom objects & Logger Console app label Sep 20, 2024
@jongpie jongpie changed the title Add new the ability to set custom fields once per transaction/on every LogEntryEvent__e record Add the ability to set custom fields once per transaction/on every LogEntryEvent__e record Sep 20, 2024
@jongpie
Copy link
Owner Author

jongpie commented Oct 16, 2024

This has been released in v4.14.14! See PR #772 for more details.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Feature: Custom Field Mappings Items related to custom field mappings functionality Layer: Log Management Items related to the custom objects & Logger Console app Layer: Logger Engine Items related to the core logging engine Logging Source: Apex Items related to using Logger within Apex Type: Bug Something isn't working Type: Enhancement New feature or request
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant