Skip to content

Commit

Permalink
Bugfix: logging no longer fails when parent transaction ID is not fou…
Browse files Browse the repository at this point in the history
…nd (#307)

* Fixed #300 by adding new field Log__c.ParentLogTransactionId__c and updated trigger handler logic to optionally set Log__c.ParentLog__c when the parent log is found/skips it when the parent log is not found

* Adding new plugin to add additional logging options for async failures (#309) for BatchApexErrorEvent and default Finalizer implementation for logging failures

* Updated the description of perm set LoggerLogCreator to indicate that it's currently optional, but might be needed in the future

* Optimized LogEntryEventHandler.TAG_ASSIGNMENT_RULES by adding lazy-loading (discussed in #303) and added a check on `LogEntryTagRule__mdt.getAll().isEmpty() == true` to minimize the usage of querying on LogEntryTagRule__mdt

* Cleaned up some methods in Logger_Tests, added TODOs for several test methods that will eventually be rewritten, alphabetized some fields in LogEntryEventBuilder

* Fixed #308 by adding the Schema namespace to a reference of FieldSetMember (now Schema.FieldSetMember)

* Further fixed issues like #308 by adding empty classes with problematic names (FieldSet, FieldSetMember, SObjectField, SObjectType and Test for now) - this will cause deployment errors in the pipeline if there are any references that don't use the System/Schema namespaces

* Removed overload for LoggerMockDataCreator.createAggregateResult(Map<String, Object>) since the current approach doesn't actually set any fields on AggregateResult
Thanks to @jamessimone for pointing this out in my last PR. Long term, I'll change the approach used for AggregateResult

* Removed some stale @SuppressWarnings annotations in a couple of Apex classes, promoted a few buried strings to be constants, and a cleaned up a few other small code bits

* Fixed some broken images in some plugin README.md

* Added CODEOWNERS file

* Changed build.yml so that the managed package build is a dependency for creating the unlocked package
This will add more time to the build, but it will ensure that the managed package (the more problematic package) can be created before creating the unlocked package

* Fixed some dependabot alerts by adding some packages in package.json's dependencies & recreating package-lock.json

Co-authored-by: James Simone <16430727+jamessimone@users.noreply.github.com>
  • Loading branch information
jongpie and jamessimone authored May 10, 2022
1 parent 3b04138 commit 7c6f49c
Show file tree
Hide file tree
Showing 95 changed files with 1,511 additions and 1,039 deletions.
1 change: 1 addition & 0 deletions .github/CODEOWNERS
Validating CODEOWNERS rules …
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
* @jongpie
56 changes: 28 additions & 28 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -235,8 +235,8 @@ jobs:
run: npm run org:delete:noprompt
if: ${{ always() }}

create-unlocked-package-release-candidate:
name: 'Create Core Package Release Candidate'
create-managed-package-beta:
name: 'Create Managed Package Beta'
needs: [lwc-tests, base-scratch-org-tests, experience-cloud-scratch-org-tests]
if: ${{ github.ref != 'refs/heads/main' }}
runs-on: ubuntu-latest
Expand Down Expand Up @@ -272,31 +272,12 @@ jobs:
DEV_HUB_CONSUMER_KEY: ${{ secrets.DEV_HUB_CONSUMER_KEY }}
DEV_HUB_JWT_SERVER_KEY: ${{ secrets.DEV_HUB_JWT_SERVER_KEY }}

- name: 'Authorize Demo Org'
shell: bash
run: |
echo ${{ env.PKG_DEMO_ORG_SFDX_URL }} > ./PKG_DEMO_ORG_SFDX_URL.txt
npx sfdx auth:sfdxurl:store --sfdxurlfile ./PKG_DEMO_ORG_SFDX_URL.txt --setalias nebula-logger-package-demo
env:
PKG_DEMO_ORG_SFDX_URL: ${{ secrets.NEBULA_PKG_DEMO_SANDBOX_SFDX_URL }}

- name: 'Create & Install Package Version'
run: npx pwsh ./scripts/build/create-and-install-package-version.ps1 -targetpackagealias '"Nebula Logger - Core"' -targetreadme ./README.md -targetusername nebula-logger-package-demo

- name: 'Commit New Package Version'
run: |
git config --local user.email "action@github.com"
git config --local user.name "GitHub Action Bot"
npm run sfdx:plugins:link:bummer
npx sfdx bummer:package:aliases:sort
npx prettier --write ./sfdx-project.json
git add ./sfdx-project.json
git commit -m "Created new package version"
git push
- name: 'Create Beta Managed Package Version'
run: npm run package:version:create:managed

create-managed-package-beta:
name: 'Create Managed Package Beta'
needs: [lwc-tests, base-scratch-org-tests, experience-cloud-scratch-org-tests]
create-unlocked-package-release-candidate:
name: 'Create Core Package Release Candidate'
needs: [create-managed-package-beta]
if: ${{ github.ref != 'refs/heads/main' }}
runs-on: ubuntu-latest
environment: 'Demo Org'
Expand Down Expand Up @@ -331,8 +312,27 @@ jobs:
DEV_HUB_CONSUMER_KEY: ${{ secrets.DEV_HUB_CONSUMER_KEY }}
DEV_HUB_JWT_SERVER_KEY: ${{ secrets.DEV_HUB_JWT_SERVER_KEY }}

- name: 'Create Beta Managed Package Version'
run: npm run package:version:create:managed
- name: 'Authorize Demo Org'
shell: bash
run: |
echo ${{ env.PKG_DEMO_ORG_SFDX_URL }} > ./PKG_DEMO_ORG_SFDX_URL.txt
npx sfdx auth:sfdxurl:store --sfdxurlfile ./PKG_DEMO_ORG_SFDX_URL.txt --setalias nebula-logger-package-demo
env:
PKG_DEMO_ORG_SFDX_URL: ${{ secrets.NEBULA_PKG_DEMO_SANDBOX_SFDX_URL }}

- name: 'Create & Install Package Version'
run: npx pwsh ./scripts/build/create-and-install-package-version.ps1 -targetpackagealias '"Nebula Logger - Core"' -targetreadme ./README.md -targetusername nebula-logger-package-demo

- name: 'Commit New Package Version'
run: |
git config --local user.email "action@github.com"
git config --local user.name "GitHub Action Bot"
npm run sfdx:plugins:link:bummer
npx sfdx bummer:package:aliases:sort
npx prettier --write ./sfdx-project.json
git add ./sfdx-project.json
git commit -m "Created new package version"
git push
promote-package-versions:
name: 'Promote Package Versions'
Expand Down
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,10 @@

Designed for Salesforce admins, developers & architects. A robust logger for Apex, Lightning Components, Flow, Process Builder & Integrations.

## Unlocked Package - v4.7.1
## Unlocked Package - v4.7.2

[![Install Unlocked Package in a Sandbox](./images/btn-install-unlocked-package-sandbox.png)](https://test.salesforce.com/packaging/installPackage.apexp?p0=04t5Y0000015lgBQAQ)
[![Install Unlocked Package in Production](./images/btn-install-unlocked-package-production.png)](https://login.salesforce.com/packaging/installPackage.apexp?p0=04t5Y0000015lgBQAQ)
[![Install Unlocked Package in a Sandbox](./images/btn-install-unlocked-package-sandbox.png)](https://test.salesforce.com/packaging/installPackage.apexp?p0=04t5Y0000015lhdQAA)
[![Install Unlocked Package in Production](./images/btn-install-unlocked-package-production.png)](https://login.salesforce.com/packaging/installPackage.apexp?p0=04t5Y0000015lhdQAA)
[![View Documentation](./images/btn-view-documentation.png)](https://jongpie.github.io/NebulaLogger/)

## Managed Package - v4.7.0
Expand Down
3 changes: 2 additions & 1 deletion config/linters/lint-staged.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ module.exports = {
return [`eslint --config ./config/linters/.eslintrc.json ${filenames.join(' ')} --fix`, `npm run test:lwc`];
},
'*.{cls,trigger}': () => {
return [`npm run lint:verify:apex`, `npm run docs:fix && git add ./docs/ && git commit --amend --no-edit`];
return [`npm run lint:verify:apex`];
// return [`npm run lint:verify:apex`, `npm run docs:fix && git add ./docs/ && git commit --amend --no-edit`];
}
};
24 changes: 2 additions & 22 deletions docs/apex/Test-Utilities/LoggerMockDataCreator.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,27 +18,7 @@ Utility class used to help with generating mock data when writing Apex tests for

#### `createAggregateResult()``AggregateResult`

Instances of `AggregateResult` can not be created directly in Apex. This method uses a workaround to generate a mock.

##### Return

**Type**

AggregateResult

**Description**

The mock instance of `AggregateResult`

#### `createAggregateResult(Map<String, Object> mockAggregateKeyValues)``AggregateResult`

Instances of `AggregateResult` can not be created directly in Apex. This method uses a workaround to generate a mock, using the provided map of aliases &amp; aggregate values

##### Parameters

| Param | Description |
| ------------------------ | --------------------------------------------------------------------------------------- |
| `mockAggregateKeyValues` | A map of aliases &amp; aggregate values to use when creating the mock `AggregateResult` |
Instances of `AggregateResult` can not be created directly in Apex. This method uses a workaround to generate a mock, although it will not have any fields or aggregate values populated on the object.

##### Return

Expand Down Expand Up @@ -611,7 +591,7 @@ A new copy of the original `SObject` record that has the specified read-only fie

#### LoggerMockDataCreator.SObjectTestDataBuilder class

Class used to create or update an `SObject` record with static fake data. This is useful in situations where you need to have fields populated, but the specific values used are not relevant to a particular test. This class can be used when Apex writing tests for plugins.
Class used to create or update an `SObject` record with static fake data. This is useful in situations where you need to have fields populated, but the specific values used are not relevant to a particular test method. This class can be used when Apex writing tests for plugins.

---

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,10 @@
<behavior>Required</behavior>
<field>SObjectHandlerApexClass__c</field>
</layoutItems>
<layoutItems>
<behavior>Edit</behavior>
<field>SObjectTypeOverride__c</field>
</layoutItems>
</layoutColumns>
<layoutColumns>
<layoutItems>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
<?xml version="1.0" encoding="UTF-8" ?>
<CustomField xmlns="http://soap.sforce.com/2006/04/metadata">
<fullName>SObjectTypeOverride__c</fullName>
<description
>Not all base platform types can be selected using the SObjectType picklist. If your object is not supported, supply the API name for the object here instead.</description>
<externalId>false</externalId>
<fieldManageability>SubscriberControlled</fieldManageability>
<inlineHelpText
>Not all base platform types can be selected using the SObjectType picklist. If your object is not supported, supply the API name for the object here instead.</inlineHelpText>
<label>SObjectType Override</label>
<length>255</length>
<required>false</required>
<type>Text</type>
<unique>false</unique>
</CustomField>
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
<referenceTo>EntityDefinition</referenceTo>
<relationshipLabel>Logger SObject Handler Configurations</relationshipLabel>
<relationshipName>LoggerSObjectHandlerConfigurations</relationshipName>
<required>true</required>
<required>false</required>
<type>MetadataRelationship</type>
<unique>true</unique>
</CustomField>
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ global with sharing class LogBatchPurger implements Database.Batchable<SObject>,
@TestVisible
private Integer chainedBatchSize = 200;
@TestVisible
private SObjectType currentSObjectType;
private Schema.SObjectType currentSObjectType;
private List<LoggerPlugin__mdt> pluginConfigurations;
private Map<BatchableMethod, List<LoggerPlugin.Batchable>> methodToExecutedApexPlugins = new Map<BatchableMethod, List<LoggerPlugin.Batchable>>();
private Map<BatchableMethod, List<Flow.Interview>> methodToExecutedFlowPlugins = new Map<BatchableMethod, List<Flow.Interview>>();
Expand Down Expand Up @@ -244,7 +244,6 @@ global with sharing class LogBatchPurger implements Database.Batchable<SObject>,
}
}

@SuppressWarnings('PMD.AvoidDebugStatements')
private void executeApexPlugin(BatchableMethod method, LoggerPlugin__mdt pluginConfiguration, LoggerBatchableContext input, List<SObject> scopeRecords) {
if (String.isBlank(pluginConfiguration.BatchPurgerApexClass__c) == true) {
return;
Expand Down Expand Up @@ -274,7 +273,6 @@ global with sharing class LogBatchPurger implements Database.Batchable<SObject>,
}
}

@SuppressWarnings('PMD.AvoidDebugStatements')
private void executeFlowPlugin(BatchableMethod method, LoggerPlugin__mdt pluginConfiguration, LoggerBatchableContext input, List<SObject> scopeRecords) {
if (String.isBlank(pluginConfiguration.BatchPurgerFlowName__c) == true) {
return;
Expand Down
Loading

0 comments on commit 7c6f49c

Please sign in to comment.