-
Notifications
You must be signed in to change notification settings - Fork 22
/
Copy pathThinkInApex.cls
44 lines (36 loc) · 1.19 KB
/
ThinkInApex.cls
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
/** With this approach, you can cache all necessary information from an object with only one SOQL call
With this approach you can run into trouble if you try to cache large amount of data.
**/
public class ThinkingInApex {
private static Boolean UserCacheLoaded = false;
private static Boolean UserIsSpecial = false;
private static String UserTimeZone = null;
public static Boolean IsUserSpecial()
{
if(UserCacheLoaded) return UserIsSpecial;
CacheUserInfo();
return UserIsSpecial:
}
public static String UserTimeZone()
{
if(UserCacheLoaded) return UserTimeZone;
CacheUserInfo();
return UserTimeZone;
}
private static void CacheUserInfo()
{
if(UserCacheLoaded) return UserTimeZone;
CacheUserInfo();
return UserTimeZone;
}
private static void CacheUserInfo()
{
if(UserCahceLoaded) return;
User u = [SELECT UserIsSpecial__c,
TimeZoneSidKey from User where
ID = :UserInfo.getUserId()];
UserIsSpecial = u.UserIsSpecial__c;
UserTimeZone = u.TimeZoneSidKey;
UserCacheLoaded = true;
}
}