Skip to content

Commit

Permalink
Added new global method (and overloads) Logger.setAsyncContext()
Browse files Browse the repository at this point in the history
  • Loading branch information
jongpie committed Sep 25, 2023
1 parent d4aeb00 commit 0a5adc2
Show file tree
Hide file tree
Showing 19 changed files with 749 additions and 100 deletions.
58 changes: 58 additions & 0 deletions docs/apex/Logger-Engine/Logger.md
Original file line number Diff line number Diff line change
Expand Up @@ -3550,6 +3550,8 @@ String

The current API version, in the format `v00.0`

#### `getPackageId()``String`

#### `getParentLogTransactionId()``String`

Returns the transaction ID value that will be used to relate the current transaction's log to a parent log
Expand Down Expand Up @@ -4850,6 +4852,46 @@ Saves any entries in Logger's buffer, using the specified save method for o
| ---------------- | ------------------------------------------------------------------------- |
| `saveMethodName` | The String value of the save method to use for this specific save action. |

#### `setAsyncContext(Database.BatchableContext batchableContext)``void`

Stores additional details about the current transacation's async context

##### Parameters

| Param | Description |
| ------------------ | ------------------------------------------------------ |
| `batchableContext` | - The instance of `Database.BatchableContext` to track |

#### `setAsyncContext(System.FinalizerContext finalizerContext)``void`

Stores additional details about the current transacation's async context

##### Parameters

| Param | Description |
| ------------------ | ---------------------------------------------------- |
| `finalizerContext` | - The instance of `System.FinalizerContext` to track |

#### `setAsyncContext(System.QueueableContext queueableContext)``void`

Stores additional details about the current transacation's async context

##### Parameters

| Param | Description |
| ------------------ | ---------------------------------------------------- |
| `queueableContext` | - The instance of `System.QueueableContext` to track |

#### `setAsyncContext(System.SchedulableContext schedulableContext)``void`

Stores additional details about the current transacation's async context

##### Parameters

| Param | Description |
| -------------------- | ------------------------------------------------------ |
| `schedulableContext` | - The instance of `System.SchedulableContext` to track |

#### `setParentLogTransactionId(String parentTransactionId)``void`

Relates the current transaction's log to a parent log via the field Log**c.ParentLog**c This is useful for relating multiple asynchronous operations together, such as batch & queueable jobs.
Expand Down Expand Up @@ -5764,14 +5806,30 @@ A string containing the UUID value.

##### Properties

###### `childJobId``String`

###### `jobId``String`

###### `key``String`

###### `name``String`

###### `triggerId``String`

###### `type``String`

---

##### Methods

###### `AsyncContext(Database.BatchableContext batchableContext)``public`

###### `AsyncContext(System.FinalizerContext finalizerContext)``public`

###### `AsyncContext(System.QueueableContext queueableContext)``public`

###### `AsyncContext(System.SchedulableContext schedulableContext)``public`

###### `insertRecords(List<SObject> records)``void`

Inserts records via the REST api.
Expand Down
122 changes: 118 additions & 4 deletions docs/apex/Test-Utilities/LoggerMockDataCreator.md
Original file line number Diff line number Diff line change
Expand Up @@ -36,9 +36,9 @@ Creates an instance of the class `MockBatchableContext` that implements the inte

##### Parameters

| Param | Description |
| ------- | --------------------------------------------------------------------------------------- |
| `jobId` | A string value to use as the batchable job ID - this can be a true ID, or just a string |
| Param | Description |
| ------- | ---------------------------------------------------------------------------------------- |
| `jobId` | A string value to use as the async Apex job ID - this can be a true ID, or just a string |

##### Return

Expand Down Expand Up @@ -338,6 +338,26 @@ Database.UpsertResult

The mock instance of `Database.UpsertResult`

#### `createFinalizerContext(String asyncApexJobId)``MockFinalizerContext`

Creates an instance of the class `MockFinalizerContext` that implements the interface `System.FinalizerContext`. This can be used when testing batch jobs.

##### Parameters

| Param | Description |
| ---------------- | ---------------------------------------------------------------------------------------- |
| `asyncApexJobId` | A string value to use as the async Apex job ID - this can be a true ID, or just a string |

##### Return

**Type**

MockFinalizerContext

**Description**

The instance of `MockFinalizerContext`

#### `createHttpCallout()``MockHttpCallout`

Generates an instance of the class `MockHttpCallout` that implements the interface `System.HttpCalloutMock`. This can be used when testing batch jobs.
Expand Down Expand Up @@ -400,6 +420,46 @@ String

The mock record ID for the specified SObject Type

#### `createQueueableContext(String jobId)``MockQueueableContext`

Creates an instance of the class `MockQueueableContext` that implements the interface `System.QueueableContext`. This can be used when testing batch jobs.

##### Parameters

| Param | Description |
| ------- | ---------------------------------------------------------------------------------------- |
| `jobId` | A string value to use as the async Apex job ID - this can be a true ID, or just a string |

##### Return

**Type**

MockQueueableContext

**Description**

The instance of `MockQueueableContext`

#### `createSchedulableContext(String jobId)``MockSchedulableContext`

Creates an instance of the class `MockSchedulableContext` that implements the interface `System.SchedulableContext`. This can be used when testing batch jobs.

##### Parameters

| Param | Description |
| ----------- | -------------------------------------------------------------------------------------- |
| `triggerId` | A string value to use as the cron trigger ID - this can be a true ID, or just a string |

##### Return

**Type**

MockSchedulableContext

**Description**

The instance of `MockSchedulableContext`

#### `createUser()``User`

Creates a `User` record for testing purposes, using the current user&apos;s profile
Expand Down Expand Up @@ -572,7 +632,7 @@ A new copy of the original `SObject` record that has the specified read-only fie

###### `MockBatchableContext(String jobId)`

###### `MockBatchableContext(String jobId, Id childJobId)`
###### `MockBatchableContext(String jobId, String childJobId)`

---

Expand All @@ -584,6 +644,28 @@ A new copy of the original `SObject` record that has the specified read-only fie

---

#### LoggerMockDataCreator.MockFinalizerContext class

---

##### Constructors

###### `MockFinalizerContext(String asyncApexJobId)`

---

##### Methods

###### `getAsyncApexJobId()``String`

###### `getException()``Exception`

###### `getRequestId()``Id`

###### `getResult()``System.ParentJobResult`

---

#### LoggerMockDataCreator.MockHttpCallout class

---
Expand Down Expand Up @@ -620,6 +702,38 @@ A new copy of the original `SObject` record that has the specified read-only fie

---

#### LoggerMockDataCreator.MockQueueableContext class

---

##### Constructors

###### `MockQueueableContext(String jobId)`

---

##### Methods

###### `getJobId()``String`

---

#### LoggerMockDataCreator.MockSchedulableContext class

---

##### Constructors

###### `MockSchedulableContext(String triggerId)`

---

##### Methods

###### `getTriggerId()``String`

---

#### 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 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 @@ -148,6 +148,10 @@ public without sharing class LogEntryEventHandler extends LoggerSObjectHandler {
// TODO Log__c.ApiVersion__c and LogEntryEvent__e.ApiVersion__c are both deprecated,
// in a future release, remove this reference (and delete the fields)
ApiVersion__c = logEntryEvent.ApiVersion__c,
AsyncContextChildJobId__c = logEntryEvent.AsyncContextChildJobId__c,
AsyncContextParentJobId__c = logEntryEvent.AsyncContextParentJobId__c,
AsyncContextTriggerId__c = logEntryEvent.AsyncContextTriggerId__c,
AsyncContextType__c = logEntryEvent.AsyncContextType__c,
ImpersonatedBy__c = logEntryEvent.ImpersonatedById__c,
Locale__c = logEntryEvent.Locale__c,
LoggedBy__c = logEntryEvent.LoggedById__c,
Expand Down
Loading

0 comments on commit 0a5adc2

Please sign in to comment.