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

Added support for custom field mappings in Apex #664

Merged
merged 12 commits into from
Jul 12, 2024

Conversation

jongpie
Copy link
Owner

@jongpie jongpie commented Apr 9, 2024

Resolves #655 by adding support for defining, setting, and mapping custom fields within Nebula Logger's data model. This is helpful in orgs that want to extend Nebula Logger's included data model by creating their own org/project-specific fields.

Adding custom fields to the platform event LogEntryEvent__e

For orgs that only use LogEntryEvent__e (and don't leverage the custom objects), they can now...

  • Create their own custom fields on LogEntryEvent__e. Any data type supported by platform events can be used.

    • In this example, a custom text field called SomeCustomField__c has been added:

      image

  • Populate their own custom fields in Apex by calling the instance method overloads LogEntryEventBuilder.setField(Schema.SObjectField field, Object fieldValue) or setField(Map<Schema.SObjectField, Object> fieldToValue).

    • For now, this functionality will only be available in Apex. Long-term, Flow & Lightning Components might also benefit from having equivalent functionality, but that will be handled separately.
    • Example: Logger.info('hello, world').setField(LogEntryEvent__e.SomeCustomField__c, 'some value');

Adding custom fields to the custom objects Log__c, LogEntry__c, and LoggerScenario__c

For orgs that want to store the data in one of Nebula Logger's custom objects, they can follow the above steps, and also...

  • Create their own custom fields on one of Nebula Logger's custom objects - right now, only Log__c, LogEntry__c, and LoggerScenario__c are supported.

    • In this example, a custom text field also called SomeCustomField__c has been added to Log__c object - this will be used to store the value of the field LogEntryEvent__e.SomeCustomField__c:

      image

  • Create a record in the new CMDT LoggerFieldMapping__mdt to map the LogEntryEvent__e custom field to the custom object's custom field, shown below. Nebula Logger will automatically populate the custom object's target field with the value of the source LogEntryEvent__e field.

    • In this example, a custom text field called SomeCustomField__c has been added to both LogEntryEvent__e and Log__c.

      image

@jongpie jongpie added Type: Enhancement New feature or request Salesforce Feature: Reporting Anything related to reports, dashboards, and the underlying data model Logging Source: Apex Items related to using Logger within Apex Layer: Configuration Items related to the custom hierarchy setting LoggerSettings__c or any included custom metadata type Layer: Log Management Items related to the custom objects & Logger Console app Layer: Logger Engine Items related to the core logging engine labels Apr 9, 2024
@jongpie jongpie had a problem deploying to Experience Cloud Scratch Org April 9, 2024 17:09 — with GitHub Actions Failure
@jongpie jongpie temporarily deployed to Experience Cloud Scratch Org April 9, 2024 18:26 — with GitHub Actions Inactive
@jongpie jongpie force-pushed the feature/custom-field-mappings branch 2 times, most recently from 12f77cb to 4ece9ca Compare April 24, 2024 03:16
@jongpie jongpie temporarily deployed to Experience Cloud Scratch Org April 24, 2024 03:20 — with GitHub Actions Inactive
@jongpie jongpie force-pushed the feature/custom-field-mappings branch from 36b8ea7 to 71af08d Compare July 7, 2024 19:12
@jongpie jongpie temporarily deployed to Experience Cloud Scratch Org July 7, 2024 19:16 — with GitHub Actions Inactive
@jongpie jongpie temporarily deployed to Base Scratch Org July 7, 2024 19:16 — with GitHub Actions Inactive
@jongpie jongpie temporarily deployed to Base Scratch Org July 7, 2024 20:06 — with GitHub Actions Inactive
@jongpie jongpie temporarily deployed to Experience Cloud Scratch Org July 7, 2024 20:06 — with GitHub Actions Inactive
…se to PascalCase

Some legacy/older validation rules use Snake_Case, but overall, PascalCase is used for all metadata in Nebula Logger
…ate methods before non-test-visible private methods
…on layer (instead of the log management layer)

It's only used by the log management layer, but since it (generically) manages field mappings, it's really part of the configuration layer
…luded custom fields (also stored in the extra-tests directory)

These CMDT records are just to help with functionally/manually testing in a scratch org - they won't be included in any of the packages
@jongpie jongpie force-pushed the feature/custom-field-mappings branch from 6be1b80 to 0ce0424 Compare July 11, 2024 18:19
@jongpie jongpie had a problem deploying to Experience Cloud Scratch Org July 11, 2024 18:24 — with GitHub Actions Failure
@jongpie jongpie temporarily deployed to Experience Cloud Scratch Org July 11, 2024 18:42 — with GitHub Actions Inactive
Copy link

codecov bot commented Jul 11, 2024

Codecov Report

Attention: Patch coverage is 84.94624% with 14 lines in your changes missing coverage. Please review.

Project coverage is 95.51%. Comparing base (48ea5fe) to head (0ce0424).

Files Patch % Lines
...e/main/configuration/classes/LoggerFieldMapper.cls 84.12% 10 Missing ⚠️
...r/core/main/configuration/classes/LoggerPlugin.cls 66.66% 2 Missing ⚠️
...ain/logger-engine/classes/LogEntryEventBuilder.cls 88.23% 2 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main     #664      +/-   ##
==========================================
- Coverage   95.66%   95.51%   -0.15%     
==========================================
  Files          50       51       +1     
  Lines        5604     5687      +83     
==========================================
+ Hits         5361     5432      +71     
- Misses        243      255      +12     
Flag Coverage Δ
Apex 95.51% <84.94%> (-0.15%) ⬇️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

jongpie and others added 2 commits July 12, 2024 13:03
This approach is more consistent with the singular naming convention used by other builder method overloads, like setRecord()
@jongpie jongpie force-pushed the feature/custom-field-mappings branch 4 times, most recently from a6f4b6d to feae243 Compare July 12, 2024 17:54
…s, and cleaned up/updated some other README contents

Also added .github/FUNDING.yml so the repo has a sponsor button
@jongpie jongpie force-pushed the feature/custom-field-mappings branch from feae243 to d4787c6 Compare July 12, 2024 18:01
@jongpie jongpie merged commit 2dbbf9f into main Jul 12, 2024
1 check passed
@jongpie jongpie deleted the feature/custom-field-mappings branch July 12, 2024 18:08
@jongpie jongpie added the Feature: Custom Field Mappings Items related to custom field mappings functionality label Jul 15, 2024
@jongpie jongpie changed the title Added support for custom field mappings Added support for custom field mappings in Apex Sep 25, 2024
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: Configuration Items related to the custom hierarchy setting LoggerSettings__c or any included custom metadata type 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 Salesforce Feature: Reporting Anything related to reports, dashboards, and the underlying data model Type: Enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Add support for setting custom fields in LogEntryEventBuilder class
3 participants