-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathSObjectUtil.cls
87 lines (81 loc) · 2.58 KB
/
SObjectUtil.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
79
80
81
82
83
84
85
86
87
/**
* @description :
* @author : Morgan Marchese @ Zoetis Inc
* @group :
* @last modified on : 05-20-2021
* @last modified by : Morgan Marchese @ Zoetis Inc
* Modifications Log
* Ver Date Author Modification
* 1.0 05-20-2021 Morgan Marchese @ Zoetis Inc Initial Version
**/
public with sharing class SObjectUtil {
private static final String FILTER_VALUE = 'United States';
// Filter US Records from INTL Records by Market
public static ObjectList filterByMarket(
List<SObject> listToFilter,
Schema.SObjectField filterField
) {
ObjectList objList = new ObjectList();
for (SObject record : listToFilter) {
if (record.get(filterField) == null)
continue;
if (record.get(filterField) == FILTER_VALUE) {
objList.objListUS.add(record);
} else {
objList.objListINTL.add(record);
}
}
return objList;
}
/*public static ObjectList filterByMarket(
List<SObject> listToFilter,
Schema.SObjectField filterField,
Schema.SObjectField parentField,
List<SObject> parentObjects,
Boolean isEqual
) {
List<SObject> recordsToBeProcessed = new List<SObject>();
Map<Id, SObject> parentObjectsMap = new Map<Id, SObject>(parentObjects);
for (SObject eachRecord : listToFilter) {
if (isEqual) {
//This is the case for US Market Accounts
if (
(parentObjectsMap.get((Id) eachRecord.get(parentField))) != null &&
(parentObjectsMap.get((Id) eachRecord.get(parentField)))
.get(filterField) != null &&
(parentObjectsMap.get((Id) eachRecord.get(parentField)))
.get(filterField) == FILTER_VALUE &&
isEqual
) {
recordsToBeProcessed.add(eachRecord);
}
} else {
//INTL Market Accounts
// two FALSE do not make a TRUE hence !isEqual
if (
(parentObjectsMap.get((Id) eachRecord.get(parentField))) != null &&
(parentObjectsMap.get((Id) eachRecord.get(parentField)))
.get(filterField) != FILTER_VALUE &&
!isEqual
) {
recordsToBeProcessed.add(eachRecord);
}
}
}
return recordsToBeProcessed;
}*/
public class ObjectList {
List<SObject> objListUS;
List<SObject> objListINTL;
public ObjectList() {
this.objListUS = new List<SObject>();
this.objListINTL = new List<SObject>();
}
public List<SObject> getUS() {
return this.objListUS;
}
public List<SObject> getINTL() {
return this.objListINTL;
}
}
}