Repository navigation
Expand file tree
/
Copy pathProfilers.cls
More file actions
185 lines (152 loc) · 6.68 KB
/
Copy pathProfilers.cls
File metadata and controls
185 lines (152 loc) · 6.68 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
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
//https://github.com/apexlarson/LimitsProfiler
//https://test.salesforce.com/packaging/installPackage.apexp?p0=04t41000002RXGo
// Visualforce page /apex/limitsprofiler
// Configure - Profiler Type: Profilers.BulkInsertProfiler
// May need to disable Standard Contact Duplicate Rule
public with sharing class Profilers
{
public class SerializationProfiler extends LimitsProfiler
{
final List<String> data;
public SerializationProfiler()
{
data = new List<String>();
for (Integer i = 0; i < 1000; i++)
data.add('a'.repeat(1000));
}
public override void execute()
{
String payload = JSON.serialize(data);
}
}
public class CloneProfiler extends LimitsProfiler
{
final Contact data;
public CloneProfiler()
{
data = new Contact();
}
public override void execute()
{
sObject theBase = data.getSObjectType().newSObject();
for (Integer i = 0; i < 1000; i++) {
sObject cleanObj = theBase.clone();
}
}
}
public class UpdateProfiler extends LimitsProfiler
{
private List<String> fieldsToCheck;
Contact c;
public UpdateProfiler()
{
}
public override void setup() {
c = new Contact();
c.LastName = 'Foo';
insert c;
fieldsToCheck = new List<String>{'LastName','FirstName','Salutation','OtherStreet','OtherCity','OtherState','OtherPostalCode','OtherCountry','OtherLatitude','OtherLongitude','MailingStreet','MailingCity','MailingState','MailingPostalCode','MailingCountry','MailingLatitude','MailingLongitude','Phone','Fax','MobilePhone','HomePhone','OtherPhone','AssistantPhone','ReportsToId','Title','Department','AssistantName','LeadSource','Birthdate','Description','EmailBouncedReason','EmailBouncedDate', 'Email'};
}
public override void execute()
{
System.assertNotEquals(null, fieldsToCheck);
ESAPI.accessController().updateAsUser(c, fieldsToCheck);
}
}
public class BulkInsertProfiler extends LimitsProfiler
{
private List<String> fieldsToCheck;
transient Savepoint sp = null;
List<Contact> c;
public BulkInsertProfiler()
{
}
public override void setup() {
sp = Database.setSavepoint();
c = new List<Contact>();
for(integer i = 0; i<200;i++) {
c.add(sampleContact(i));
}
//c = new Map<Id, Contact>(cl);
fieldsToCheck = new List<String>{'LastName','FirstName','Salutation','OtherStreet','OtherCity','OtherState','OtherPostalCode','OtherCountry','OtherLatitude','OtherLongitude','MailingStreet','MailingCity','MailingState','MailingPostalCode','MailingCountry','MailingLatitude','MailingLongitude','Phone','Fax','MobilePhone','HomePhone','OtherPhone','AssistantPhone','ReportsToId','Title','Department','AssistantName','LeadSource','Birthdate','Description','EmailBouncedReason','EmailBouncedDate', 'Email'};
}
public override void execute()
{
System.assertNotEquals(null, fieldsToCheck);
ESAPI.accessController().insertAsUser(c, fieldsToCheck);
}
public override void tearDown() {
Database.rollback(sp);
//integer remainingDML = Limits.getLimitDMLRows() - Limits.getDMLStatements() - 1000;
//delete [Select Id from Contact where Email = 'ContactEmail@example.com' limit :remainingDML];
}
}
public class BulkUpdateProfiler extends LimitsProfiler
{
private List<String> fieldsToCheck;
transient Savepoint sp = null;
List<Contact> c;
public BulkUpdateProfiler()
{
}
public override void setup() {
sp = Database.setSavepoint();
c = new List<Contact>();
for(integer i = 0; i<200;i++) {
c.add(sampleContact(i));
}
//c = new Map<Id, Contact>(cl);
insert c;
fieldsToCheck = new List<String>{'LastName','FirstName','Salutation','OtherStreet','OtherCity','OtherState','OtherPostalCode','OtherCountry','OtherLatitude','OtherLongitude','MailingStreet','MailingCity','MailingState','MailingPostalCode','MailingCountry','MailingLatitude','MailingLongitude','Phone','Fax','MobilePhone','HomePhone','OtherPhone','AssistantPhone','ReportsToId','Title','Department','AssistantName','LeadSource','Birthdate','Description','EmailBouncedReason','EmailBouncedDate', 'Email'};
}
public override void execute()
{
System.assertNotEquals(null, fieldsToCheck);
ESAPI.accessController().updateAsUser(new Map<Id, Contact>(c), fieldsToCheck);
}
public override void tearDown() {
Database.rollback(sp);
//integer remainingDML = Limits.getLimitDMLRows() - Limits.getDMLStatements() - 1000;
//delete [Select Id from Contact where Email = 'ContactEmail@example.com' limit :remainingDML];
}
}
public static Contact sampleContact(integer i) {
Contact c = new Contact();
c.LastName='Foo' + i;
c.FirstName='Bar' + i;
c.Salutation='Zer';
c.Birthdate=Date.newInstance(2019, 10, 17);
c.Department='Testing';
c.OtherStreet = 'OtherStreet';
c.OtherCity = 'OtherCity';
c.OtherState = 'OtherState';
c.OtherPostalCode = 'OtherPostalCode';
c.OtherCountry = 'OtherCountry';
c.OtherLatitude = 1;
c.OtherLongitude = 1;
c.MailingStreet = 'MailingStreet';
c.MailingCity = 'MailingCity';
c.MailingState = 'MailingState';
c.MailingPostalCode = 'MailingPostalCode';
c.MailingCountry = 'MailingCountry';
c.MailingLatitude = 1;
c.MailingLongitude = 1;
c.Phone = 'Phone' + i;
c.Fax = 'Fax';
c.MobilePhone = 'MobilePhone';
c.HomePhone = 'HomePhone';
c.OtherPhone = 'OtherPhone';
c.AssistantPhone = 'AssistantPhone';
c.Title = 'Title';
c.Department = 'Department';
c.AssistantName = 'AssistantName';
c.LeadSource = 'LeadSource';
c.Birthdate = DateTime.now().Date();
c.Description = 'Description';
c.EmailBouncedReason = 'EmailBouncedReason';
c.EmailBouncedDate = DateTime.now();
c.Email = 'ContactEmail@example.com';
c.ReportsToId = null;
return c;
}
}