-
Notifications
You must be signed in to change notification settings - Fork 1
/
us_example.cls
70 lines (59 loc) · 3.39 KB
/
us_example.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
/* All Examples come here. */
public class us_example {
/* Creates a Map of a employee's Reporting Line
* You must initialize the class by passing in a map with all users.
* How to test (Independently):
* Map<Id, User> all_users = new Map<Id, User>([Id, ManagerId, Manager.ManagerID, Manager.Manager.ManagerId, Manager.Manager.Manager.ManagerId from User where Department = 'IS' or Department = '']);
* User jawaad = all_users.get('...');
* ReportingLineMapId = new ReportingLineMapId(all_users);
* system.debug(ReportingLineMapId.groupBy(new List<User>{jawaad}));
*
* Or with US it would be
* US all_users = new US([Id, ManagerId, Manager.ManagerID, Manager.Manager.ManagerId, Manager.Manager.Manager.ManagerId from User where Department = 'IS' or Department = '']);
* Map<Id, List<User>> reporting_lines = = all_users.filter('Alias', 'jawaad').groupby(new ReportingLineMapId(all_users));
*
*/
class ReportingLineMapId implements US.GroupByInterface {
public Map<Id, User> AllUsers;
public ReportingLineMapId(Map<Id, User> all_users){
AllUsers = all_users; // This is a map of all users who exist.
}
public Map<String, List<Object>> groupBy(List<Object> objs){ // objs = requesting users.
Map<String, List<User>> ret = new Map<String, List<User>>();
for (Object u: objs){
List<User> ReportingLine = new List<User>();
User y = (User) u;
while (y.ManagerId != null && AllUsers.get(y.ManagerId) != null){
ReportingLine.add(AllUsers.get(y.ManagerId));
y = AllUsers.get(y.ManagerId);
}
ret.put(((User) u).Id, ReportingLine);
}
return ret;
}
}
public static void how_to_user(){
Map<Id, User> all_users = new Map<Id, User>([Select Id, name, COA_Acronym__c, COA_Group__c, ManagerId, Manager.ManagerID, Manager.Manager.ManagerId, Manager.Manager.Manager.ManagerId
from User where isActive=true]);
US all_users_us = new us(all_users.values());
Map<String, List<User>> ReportingLines = (Map<String, List<User>>) all_users_us.filter('alias', 'jawaad').groupBy(ReportingLineMapId(Map<String, List<User>>.class, all_users));
List<User> jawaad_reporting_line = ReportingLines.get(jawaad.id));
}
}
// You must run the batch job if we transition from StartBatchJobStartStatus to TriggerWebServiceBatchStatus
// Demos how we can use OL if we don't want to reuse the US object later.
public with sharing class Custom_Object_TriggerActions {
public static Map<Id, SObject> oldApp;
final static Set<String> ValidEndStatus = new Set<String> {'Approved', 'Resubmit'};
final static Set<String> ValidStartStatus = new Set<String> {'Awaiting Financial Approval', 'Circulating'};
public class OldRequestStatusChange extends US.FilterInterfaceAbstract {
public override boolean filterfn(List<SObject> memo, SObject value){
return ValidStartStatus.contains((String) OldApp.get(value.Id).get('Status__c'));
}
}
public static void calloutApprovedInformation(List<SObject> new_list, Map<Id, SObject> old_map) {
oldApp = old_map;
if(US.OL(new_list).filter('Status__c', ValidEndStatus).some(new OldRequestStatusChange()))
BulkCallWebService_Batch.startBatch(true);
}
}