-
-
Notifications
You must be signed in to change notification settings - Fork 232
Expand file tree
/
Copy pathLoggerSObjectProxy.cls
More file actions
84 lines (79 loc) · 4.24 KB
/
LoggerSObjectProxy.cls
File metadata and controls
84 lines (79 loc) · 4.24 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
//------------------------------------------------------------------------------------------------//
// 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. //
//------------------------------------------------------------------------------------------------//
/**
* @group Logger Engine
* @description Proxy class used as a middle layer between some problematic SObject Types and the rest of Nebula Logger's codebase.
* Each inner class maps to a corresponding `SObjectType` that is difficult to work with Apex for some reason or another,
* such as not being mockable or creatable, or not existing in all orgs.
*/
public without sharing class LoggerSObjectProxy {
/**
* @description All `Schema.AuthSession` SObjects are read-only in Apex, which makes them more difficult to work with, and impossible
* to mock field values directly during unit tests - even using tricks like System.JSON.deserialize() do not work. The `LoggerSObjectProxy.AuthSession`
* class acts as a substitute for a `Schema.AuthSession` record to provide the abilility to mock the data during unit & integration tests.
*/
@SuppressWarnings('PMD.FieldNamingConventions, PMD.VariableNamingConventions')
public class AuthSession extends SObjectProxy {
public Id Id;
public String LoginType;
public Id LoginHistoryId;
public LoginHistory LoginHistory;
public String LogoutUrl;
public Id ParentId;
public String SessionSecurityLevel;
public String SessionType;
public String SourceIp;
public Id UsersId;
public Boolean IsAssociatedWithJwtAccessToken;
}
/**
* @description All `Schema.LoginHistory` SObjects are read-only in Apex, which makes them more difficult to work with, and impossible
* to mock field values directly during unit tests - even using tricks like System.JSON.deserialize() do not work. The `LoggerSObjectProxy.LoginHistory`
* class acts as a substitute for a `Schema.LoginHistory` record to provide the abilility to mock the data during unit & integration tests.
*/
@SuppressWarnings('PMD.FieldNamingConventions, PMD.VariableNamingConventions')
public class LoginHistory extends SObjectProxy {
public String Application;
public String Browser;
public String Platform;
public Id UserId;
}
/**
* @description Not all orgs have the SObject `Schema.Network` - it is only present in orgs that have enabled Experience Cloud Sites (communities/networks),
* so `Schema.Network` has to be referenced dynamically, including using hardcoded `String` values for field API names. The
* `LoggerSObjectProxy.Network` class acts as a substitute for a `Schema.Network` record so that the rest of the codebase can rely on
* strongly-typed references to fields (properties).
*/
@SuppressWarnings('PMD.FieldNamingConventions, PMD.VariableNamingConventions')
public class Network extends SObjectProxy {
public String Id;
public String Name;
public String UrlPathPrefix;
}
/**
* @description Not all orgs have the SObject `Schema.OmniProcess` - it is only present in orgs that have enabled OmniStudio,
* so `Schema.OmniProcess` has to be referenced dynamically, including using hardcoded `String` values for field API names. The
* `LoggerSObjectProxy.OmniProcess` class acts as a substitute for a `Schema.OmniProcess` record so that the rest of the codebase can rely on
* strongly-typed references to fields (properties).
*/
@SuppressWarnings('PMD.FieldNamingConventions, PMD.VariableNamingConventions')
public class OmniProcess extends SObjectProxy {
public Id CreatedById;
public Schema.User CreatedBy;
public Datetime CreatedDate;
public String Id;
public Id LastModifiedById;
public Schema.User LastModifiedBy;
public Datetime LastModifiedDate;
public String OmniProcessType;
public String UniqueName;
}
@SuppressWarnings('PMD.ApexDoc')
private abstract class SObjectProxy {
public String serialize() {
return System.JSON.serializePretty(this);
}
}
}