Skip to content

Commit

Permalink
Switched to using fully-qualified references to Schema.AsyncApexJob, …
Browse files Browse the repository at this point in the history
…Schema.BatchApexErrorEvent, Schema.CustomPermission, Schema.FlowExecutionErrorEvent, Schema.PermissionSet, Schema.PermissionSetAssignment, Schema.UserRole, System.BatchableContext, and System.FinalizerContext
  • Loading branch information
jongpie committed Jul 10, 2024
1 parent cab6f77 commit ebd342a
Show file tree
Hide file tree
Showing 32 changed files with 202 additions and 53 deletions.
10 changes: 5 additions & 5 deletions docs/apex/Log-Management/LogBatchPurgeController.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,19 +24,19 @@ Boolean

true if the current user has delete permission on the Log\_\_c object.

#### `getBatchPurgeJobRecords()``List<AsyncApexJob>`
#### `getBatchPurgeJobRecords()``List<Schema.AsyncApexJob>`

Returns `List&lt;AsyncApexJob&gt;` to display logBatchPurger jobs details in a Datatable.
Returns `List&lt;Schema.AsyncApexJob&gt;` to display logBatchPurger jobs details in a Datatable.

##### Return

**Type**

List&lt;AsyncApexJob&gt;
List&lt;Schema.AsyncApexJob&gt;

**Description**

The instance of `List&lt;AsyncApexJob&gt;`, containing list of logBatchPurge jobs.
The instance of `List&lt;Schema.AsyncApexJob&gt;`, containing list of logBatchPurge jobs.

#### `getMetrics(String dateFilterOption)``Map<String, Object>`

Expand Down Expand Up @@ -84,7 +84,7 @@ String

**Description**

Returns the ID of the AsyncApexJob object associated with the LogBatchPurger job as a string
Returns the ID of the Schema.AsyncApexJob object associated with the LogBatchPurger job as a string

---

Expand Down
12 changes: 6 additions & 6 deletions docs/apex/Log-Management/LogManagementDataSelector.md
Original file line number Diff line number Diff line change
Expand Up @@ -123,15 +123,15 @@ The cached `Log__c` record, or `null` if no match is found

#### `getCountOfAsyncApexJobs(String apexClassName, String apexMethodName, List<String> jobStatuses)``Integer`

Returns the count of `AsyncApexJob` records with the specified Apex class name, method name &amp; job status
Returns the count of `Schema.AsyncApexJob` records with the specified Apex class name, method name &amp; job status

##### Parameters

| Param | Description |
| ---------------- | --------------------------------------------------------------------------------- |
| `apexClassName` | The fully-qualified name of the Apex class associated with `AsyncApexJob` |
| `apexMethodName` | The specific method (if any) within the Apex class associated with `AsyncApexJob` |
| `jobStatuses` | The list of job statuses that should be used to filter `AsynxApexJob` records |
| Param | Description |
| ---------------- | ---------------------------------------------------------------------------------------- |
| `apexClassName` | The fully-qualified name of the Apex class associated with `Schema.AsyncApexJob` |
| `apexMethodName` | The specific method (if any) within the Apex class associated with `Schema.AsyncApexJob` |
| `jobStatuses` | The list of job statuses that should be used to filter `AsynxApexJob` records |

##### Return

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,11 +65,11 @@ public with sharing class LogBatchPurgeController {
}

/**
* @description Returns `List<AsyncApexJob>` to display logBatchPurger jobs details in a Datatable.
* @return The instance of `List<AsyncApexJob>`, containing list of logBatchPurge jobs.
* @description Returns `List<Schema.AsyncApexJob>` to display logBatchPurger jobs details in a Datatable.
* @return The instance of `List<Schema.AsyncApexJob>`, containing list of logBatchPurge jobs.
*/
@AuraEnabled
public static List<AsyncApexJob> getBatchPurgeJobRecords() {
public static List<Schema.AsyncApexJob> getBatchPurgeJobRecords() {
List<String> qualifiedClassNamePieces = LogBatchPurger.class.getName().split('\\.');
// If there are 2 pieces, then it
String apexClassNamespacePrefix = qualifiedClassNamePieces.size() == 2 ? qualifiedClassNamePieces.get(0) : null;
Expand All @@ -89,7 +89,7 @@ public with sharing class LogBatchPurgeController {

/**
* @description execute the logBatchPurger batch with batch size 2000
* @return Returns the ID of the AsyncApexJob object associated with the LogBatchPurger job as a string
* @return Returns the ID of the Schema.AsyncApexJob object associated with the LogBatchPurger job as a string
*/
@AuraEnabled
public static String runBatchPurge() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -136,9 +136,9 @@ public without sharing virtual class LogManagementDataSelector {
}

/**
* @description Returns the count of `AsyncApexJob` records with the specified Apex class name, method name & job status
* @param apexClassName The fully-qualified name of the Apex class associated with `AsyncApexJob`
* @param apexMethodName The specific method (if any) within the Apex class associated with `AsyncApexJob`
* @description Returns the count of `Schema.AsyncApexJob` records with the specified Apex class name, method name & job status
* @param apexClassName The fully-qualified name of the Apex class associated with `Schema.AsyncApexJob`
* @param apexMethodName The specific method (if any) within the Apex class associated with `Schema.AsyncApexJob`
* @param jobStatuses The list of job statuses that should be used to filter `AsynxApexJob` records
* @return The `Integer` count of matching `AsynxApexJob` records
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -317,13 +317,16 @@ private class LogBatchPurgeController_Tests {
static void it_should_permit_user_to_execute_purge_batch_when_custom_permission_is_assigned() {
Schema.User standardUser = LoggerMockDataCreator.createUser(STANDARD_USER_PROFILE.Id);
insert standardUser;
PermissionSet permissionSet = new PermissionSet(Name = 'CanExecuteLogBatchPurger', Label = 'Custom Permisison Enabled');
Schema.PermissionSet permissionSet = new Schema.PermissionSet(Name = 'CanExecuteLogBatchPurger', Label = 'Custom Permisison Enabled');
insert permissionSet;
SetupEntityAccess setupEntityAccess = new SetupEntityAccess(
ParentId = permissionSet.Id,
SetupEntityId = getCanExecuteLogBatchPurgerCustomPermissionId()
);
PermissionSetAssignment permissionSetAssignment = new PermissionSetAssignment(AssigneeId = standardUser.Id, PermissionSetId = permissionSet.Id);
Schema.PermissionSetAssignment permissionSetAssignment = new Schema.PermissionSetAssignment(
AssigneeId = standardUser.Id,
PermissionSetId = permissionSet.Id
);
insert new List<SObject>{ setupEntityAccess, permissionSetAssignment };

System.runAs(standardUser) {
Expand All @@ -344,9 +347,9 @@ private class LogBatchPurgeController_Tests {
System.Test.startTest();
LogBatchPurgeController.runBatchPurge();
System.Test.stopTest();
List<AsyncApexJob> purgeJobs = LogBatchPurgeController.getBatchPurgeJobRecords();
List<Schema.AsyncApexJob> purgeJobs = LogBatchPurgeController.getBatchPurgeJobRecords();
System.Assert.areEqual(1, purgeJobs.size(), 'should return purge batch job records');
for (AsyncApexJob job : purgeJobs) {
for (Schema.AsyncApexJob job : purgeJobs) {
System.Assert.isNotNull(job.JobType, 'it should return job type');
System.Assert.isNotNull(job.JobItemsProcessed, 'it should return JobItemsProcessed');
System.Assert.isNotNull(job.NumberOfErrors, 'it should return noOfErrors');
Expand All @@ -360,7 +363,7 @@ private class LogBatchPurgeController_Tests {
static void it_should_not_permit_user_to_execute_purge_batch_when_custom_permission_is_not_assigned() {
Schema.User standardUser = LoggerMockDataCreator.createUser(STANDARD_USER_PROFILE.Id);
insert standardUser;
PermissionSet permissionSet = new PermissionSet(Name = 'CanExecuteLogBatchPurger', Label = 'Custom Permisison Enabled');
Schema.PermissionSet permissionSet = new Schema.PermissionSet(Name = 'CanExecuteLogBatchPurger', Label = 'Custom Permisison Enabled');
insert permissionSet;
SetupEntityAccess setupEntityAccess = new SetupEntityAccess(
ParentId = permissionSet.Id,
Expand Down Expand Up @@ -388,7 +391,7 @@ private class LogBatchPurgeController_Tests {
String apexClassName = LogBatchPurger.class.getName().contains('.')
? LogBatchPurger.class.getName().substringAfter('.')
: LogBatchPurger.class.getName();
List<AsyncApexJob> purgeBatchJobs = [
List<Schema.AsyncApexJob> purgeBatchJobs = [
SELECT Id
FROM AsyncApexJob
WHERE
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ private class LogManagementDataSelector_Tests {
// executeSomeFutureMethod();
// System.Test.stopTest();

// System.Assert.fail([SELECT status FROM asyncapexjob]);
// System.Assert.fail([SELECT status FROM AsyncApexJob]);
// Integer returnedCount = LogManagementDataSelector.getInstance().getCountOfAsyncApexJobs(apexClassName, apexMethodName, jobStatuses);

// System.Assert.areEqual(1, returnedCount);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
*/
@IsTest
public without sharing class LoggerTestConfigurator {
private static final Map<String, PermissionSet> PERMISSION_SETS_BY_NAME = queryPermissionSets();
private static final Map<String, Schema.PermissionSet> PERMISSION_SETS_BY_NAME = queryPermissionSets();

/**
* @description Assigns the permission set `LoggerAdmin` to the specified user ID
Expand Down Expand Up @@ -146,15 +146,15 @@ public without sharing class LoggerTestConfigurator {
}

// Helper methods
private static void assignPermissionSet(Id userId, PermissionSet permissionSet) {
PermissionSetAssignment permissionSetAssignment = new PermissionSetAssignment(AssigneeId = userId, PermissionSetId = permissionSet.Id);
private static void assignPermissionSet(Id userId, Schema.PermissionSet permissionSet) {
Schema.PermissionSetAssignment permissionSetAssignment = new Schema.PermissionSetAssignment(AssigneeId = userId, PermissionSetId = permissionSet.Id);
insert permissionSetAssignment;
}

private static Map<String, PermissionSet> queryPermissionSets() {
private static Map<String, Schema.PermissionSet> queryPermissionSets() {
List<String> permissionSetNames = new List<String>{ 'LoggerAdmin', 'LoggerLogViewer', 'LoggerEndUser', 'LoggerLogCreator' };
Map<String, PermissionSet> results = new Map<String, PermissionSet>();
for (PermissionSet permissionSet : [SELECT Id, Name FROM PermissionSet WHERE Name IN :permissionSetNames]) {
Map<String, Schema.PermissionSet> results = new Map<String, Schema.PermissionSet>();
for (Schema.PermissionSet permissionSet : [SELECT Id, Name FROM PermissionSet WHERE Name IN :permissionSetNames]) {
results.put(permissionSet.Name, permissionSet);
}
return results;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
//------------------------------------------------------------------------------------------------//
// This file is part of the Nebula Logger project, released under the MIT License. //
// See LICENSE file or go to https://github.com/jongpie/NebulaLogger for full license details. //
//------------------------------------------------------------------------------------------------//

// This class intentionally does nothing - it's here to ensure that any references
// in Nebula Logger's codebase use `Schema.AsyncApexJob` instead of just `AsyncApexJob`
@SuppressWarnings('PMD.ApexDoc, PMD.EmptyStatementBlock')
public without sharing class AsyncApexJob {
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
<?xml version="1.0" encoding="UTF-8" ?>
<ApexClass xmlns="http://soap.sforce.com/2006/04/metadata">
<apiVersion>60.0</apiVersion>
<status>Active</status>
</ApexClass>
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
//------------------------------------------------------------------------------------------------//
// This file is part of the Nebula Logger project, released under the MIT License. //
// See LICENSE file or go to https://github.com/jongpie/NebulaLogger for full license details. //
//------------------------------------------------------------------------------------------------//

// This class intentionally does nothing - it's here to ensure that any references
// in Nebula Logger's codebase use `Schema.BatchApexErrorEvent` instead of just `BatchApexErrorEvent`
@SuppressWarnings('PMD.ApexDoc, PMD.EmptyStatementBlock')
public without sharing class BatchApexErrorEvent {
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
<?xml version="1.0" encoding="UTF-8" ?>
<ApexClass xmlns="http://soap.sforce.com/2006/04/metadata">
<apiVersion>60.0</apiVersion>
<status>Active</status>
</ApexClass>
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
//------------------------------------------------------------------------------------------------//
// This file is part of the Nebula Logger project, released under the MIT License. //
// See LICENSE file or go to https://github.com/jongpie/NebulaLogger for full license details. //
//------------------------------------------------------------------------------------------------//

// This class intentionally does nothing - it's here to ensure that any references
// in Nebula Logger's codebase use `Schema.CustomPermission` instead of just `CustomPermission`
@SuppressWarnings('PMD.ApexDoc, PMD.EmptyStatementBlock')
public without sharing class CustomPermission {
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
<?xml version="1.0" encoding="UTF-8" ?>
<ApexClass xmlns="http://soap.sforce.com/2006/04/metadata">
<apiVersion>60.0</apiVersion>
<status>Active</status>
</ApexClass>
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
//------------------------------------------------------------------------------------------------//
// This file is part of the Nebula Logger project, released under the MIT License. //
// See LICENSE file or go to https://github.com/jongpie/NebulaLogger for full license details. //
//------------------------------------------------------------------------------------------------//

// This class intentionally does nothing - it's here to ensure that any references
// in Nebula Logger's codebase use `Schema.FlowExecutionErrorEvent` instead of just `FlowExecutionErrorEvent`
@SuppressWarnings('PMD.ApexDoc, PMD.EmptyStatementBlock')
public without sharing class FlowExecutionErrorEvent {
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
<?xml version="1.0" encoding="UTF-8" ?>
<ApexClass xmlns="http://soap.sforce.com/2006/04/metadata">
<apiVersion>60.0</apiVersion>
<status>Active</status>
</ApexClass>
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
//------------------------------------------------------------------------------------------------//
// This file is part of the Nebula Logger project, released under the MIT License. //
// See LICENSE file or go to https://github.com/jongpie/NebulaLogger for full license details. //
//------------------------------------------------------------------------------------------------//

// This class intentionally does nothing - it's here to ensure that any references
// in Nebula Logger's codebase use `Schema.PermissionSet` instead of just `PermissionSet`
@SuppressWarnings('PMD.ApexDoc, PMD.EmptyStatementBlock')
public without sharing class PermissionSet {
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
<?xml version="1.0" encoding="UTF-8" ?>
<ApexClass xmlns="http://soap.sforce.com/2006/04/metadata">
<apiVersion>60.0</apiVersion>
<status>Active</status>
</ApexClass>
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
//------------------------------------------------------------------------------------------------//
// This file is part of the Nebula Logger project, released under the MIT License. //
// See LICENSE file or go to https://github.com/jongpie/NebulaLogger for full license details. //
//------------------------------------------------------------------------------------------------//

// This class intentionally does nothing - it's here to ensure that any references
// in Nebula Logger's codebase use `Schema.PermissionSetAssignment` instead of just `PermissionSetAssignment`
@SuppressWarnings('PMD.ApexDoc, PMD.EmptyStatementBlock')
public without sharing class PermissionSetAssignment {
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
<?xml version="1.0" encoding="UTF-8" ?>
<ApexClass xmlns="http://soap.sforce.com/2006/04/metadata">
<apiVersion>60.0</apiVersion>
<status>Active</status>
</ApexClass>
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
//------------------------------------------------------------------------------------------------//
// This file is part of the Nebula Logger project, released under the MIT License. //
// See LICENSE file or go to https://github.com/jongpie/NebulaLogger for full license details. //
//------------------------------------------------------------------------------------------------//

// This class intentionally does nothing - it's here to ensure that any references
// in Nebula Logger's codebase use `Schema.UserRole` instead of just `UserRole`
@SuppressWarnings('PMD.ApexDoc, PMD.EmptyStatementBlock')
public without sharing class UserRole {
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
<?xml version="1.0" encoding="UTF-8" ?>
<ApexClass xmlns="http://soap.sforce.com/2006/04/metadata">
<apiVersion>60.0</apiVersion>
<status>Active</status>
</ApexClass>
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
//------------------------------------------------------------------------------------------------//
// This file is part of the Nebula Logger project, released under the MIT License. //
// See LICENSE file or go to https://github.com/jongpie/NebulaLogger for full license details. //
//------------------------------------------------------------------------------------------------//

// This class intentionally does nothing - it's here to ensure that any references
// in Nebula Logger's codebase use `Schema.BatchableContext` instead of just `BatchableContext`
@SuppressWarnings('PMD.ApexDoc, PMD.EmptyStatementBlock')
public without sharing class BatchableContext {
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
<?xml version="1.0" encoding="UTF-8" ?>
<ApexClass xmlns="http://soap.sforce.com/2006/04/metadata">
<apiVersion>60.0</apiVersion>
<status>Active</status>
</ApexClass>
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
//------------------------------------------------------------------------------------------------//
// This file is part of the Nebula Logger project, released under the MIT License. //
// See LICENSE file or go to https://github.com/jongpie/NebulaLogger for full license details. //
//------------------------------------------------------------------------------------------------//

// This class intentionally does nothing - it's here to ensure that any references
// in Nebula Logger's codebase use `Schema.FinalizerContext` instead of just `FinalizerContext`
@SuppressWarnings('PMD.ApexDoc, PMD.EmptyStatementBlock')
public without sharing class FinalizerContext {
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
<?xml version="1.0" encoding="UTF-8" ?>
<ApexClass xmlns="http://soap.sforce.com/2006/04/metadata">
<apiVersion>60.0</apiVersion>
<status>Active</status>
</ApexClass>
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ private class LogEntryEventBuilder_Tests_Network {
}

static Schema.User setupExperienceSiteUser() {
UserRole userRole = new UserRole(DeveloperName = 'LoggerTestRole', Name = 'Logger Test Role');
Schema.UserRole userRole = new Schema.UserRole(DeveloperName = 'LoggerTestRole', Name = 'Logger Test Role');
insert userRole;
Schema.User currentUser = new Schema.User(Id = System.UserInfo.getUserId(), UserRoleId = userRole.Id);
update currentUser;
Expand Down
Loading

0 comments on commit ebd342a

Please sign in to comment.