-
Notifications
You must be signed in to change notification settings - Fork 22
/
FieldLevelHistory.cls
37 lines (31 loc) · 1.17 KB
/
FieldLevelHistory.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
public class FieldLevelHistory {
public Datetime CreatedDate { get; set; }
public Id CreatedById { get; set; }
public Object NewValue { get; set; }
public Object OldValue { get; set; }
public String Field { get; set; }
public Id ParentId { get; private set; }
private String parentLookupName = 'ParentId';
public override String toString() {
return JSON.serialize(this);
}
public FieldLevelHistory setValues(Map<String, Object> values) {
this.CreatedById = (Id) values.get('CreatedById');
Object possibleCreatedDate = values.get('CreatedDate');
this.CreatedDate = Datetime.valueOfGmt(String.valueOf(possibleCreatedDate).replace('T', ' ').remove('"'));
this.Field = (String) values.get('Field');
this.NewValue = values.get('NewValue');
this.OldValue = values.get('OldValue');
this.setParentId(values);
return this;
}
public FieldLevelHistory setParentLookup(Schema.SObjectField fieldToken) {
if (fieldToken != null) {
this.parentLookupName = fieldToken.getDescribe().getName();
}
return this;
}
private void setParentId(Map<String, Object> values) {
this.ParentId = (Id) values.get(this.parentLookupName);
}
}