-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathThinkingInApex.cls
More file actions
47 lines (39 loc) · 1.41 KB
/
ThinkingInApex.cls
File metadata and controls
47 lines (39 loc) · 1.41 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
/* centralizing access of a potentially multiple times used value (caching data)
*
* obtain such information summoning ThinkingInApex.isUserSpecial() from anywhere in your
* code without worrying about making redundant SOQL calls. */
public class ThinkingInApex {
private static boolean userCacheLoaded = false;
private static boolean userIsSpecial = false;
private static string userTimeZone = null;
public static boolean isUserSpecial() {
// if we already have the value, then return it.
if(userCacheLoaded)
return userIsSpecial;
// else get the cached info and return the desired value
cacheUserInfo();
return userIsSpecial;
}
// same procedure
public static string userTimeZone() {
if(userCacheLoaded)
return userTimeZone;
cacheUserInfo();
return userTimeZone;isUserSpecialChecked
}
private static void cacheUserInfo() {
if(userCacheLoaded)
return;
// retrieve userIsSpecial values
User u = [
SELECT userIsSpecial__c, TimeZoneSidKey
FROM User
WHERE Id = :UserInfo.getUserId()
];
/* now we get the values, we turn on the userCacheLoaded to true
* and return our desired value */
userIsSpecial = u.userIsSpecial__c;
userTimeZone = u.TimeZoneSidKey;
userCacheLoaded = true;
}
}