-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathDAL_User.cls
78 lines (71 loc) · 1.99 KB
/
DAL_User.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
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
public class DAL_User
{
private static final String USER_TYPE_STANDARD = 'Standard';
public static final String FIELD_EMAIL_ENCODING_KEY = User.EmailEncodingKey.getDescribe().getLocalName();
public static final String OBJECT_NAME = User.sObjectType.getDescribe().getLocalName();
public static User getCurrentUser()
{
User user;
try
{
user =
[
SELECT
Id,
Email
FROM
User
WHERE
Username = :UserInfo.getUserName()
LIMIT 1
];
}
catch (QueryException e)
{
System.debug('DAL_User.getCurrentUser:' + e.getStackTraceString());
}
return user;
}
public static List<User> getByIds(Set<Id> userIds)
{
List<User> users = new List<User>();
try
{
users =
[
SELECT
Id,
Name,
Firstname,
LastName,
Email
FROM
User
WHERE
Id IN :userIds
];
}
catch(QueryException e)
{
System.debug('DAL_User.getByIds:' + e.getStackTraceString());
}
return users;
}
public static List<User> getActiveUsers()
{
return
[
SELECT Id, Name
FROM User
WHERE IsActive = true
AND UserType = :USER_TYPE_STANDARD
];
}
public static User getRandomActiveUser()
{
List<User> users = getActiveUsers();
System.assert(!users.isEmpty());
Integer index = al.RandomUtils.nextInteger(users.size() - 1);
return users[index];
}
}