-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathCTRL_PickListDescriber.cls
59 lines (48 loc) · 1.95 KB
/
CTRL_PickListDescriber.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
/**
Visualforce controller for a page that renders the XML output Pick List values on Custom or Standard Objects
Original code was sourced from https://github.com/abhinavguptas/Multi-RecordType-Sobject-Picklist-Describer.git
*/
public class CTRL_PickListDescriber
{
public SObject SObj {get;set;}
public String PickListFieldName {get;set;}
public CTRL_PickListDescriber()
{
Map<String, String> requiredParameters = ApexPages.currentPage().getParameters();
String sobjId = requiredParameters.get(UTIL_PickList.PARAM_OBJECT_ID);
PickListFieldName = requiredParameters.get(UTIL_PickList.PARAM_PICK_LIST_NAME);
String sobjectTypeName = requiredParameters.get(UTIL_PickList.PARAM_OBJECT_TYPE);
if (String.isNotBlank(sObjId))
{
SObj = Database.query(
new al.SoqlBuilder()
.selectx(PickListFieldName)
.fromx(sobjectTypeName)
.wherex(new al.FieldCondition(DAL_BaseObject.ID_FIELD, sobjId))
.toSoql(new al.SoqlOptions().escapeSingleQuotes())
);
}
else
{
//Construct an SObject using it's API Name
SObj = DAL_BaseObject.newObject(sobjectTypeName);
if (SObj != null)
{
String recordTypeName = requiredParameters.get(UTIL_PickList.PARAM_RECORD_TYPE);
if (String.isNotBlank(recordTypeName))
{
Id recordTypeId = DAL_BaseObject.getRecordTypeByDeveloperName(SObj.getSObjectType(), recordTypeName);
if (recordTypeId != null)
{
//Get all the recordtypes available for this object, if one of them matches
//the name of the passed recordtype name, then assign it to the SObject (if the user is allowed access)
Map<Id, Schema.RecordTypeInfo> recordTypes = SObj.getSObjectType().getDescribe().getRecordTypeInfosById();
Schema.RecordTypeInfo recordType = recordTypes.get(recordTypeId);
if (recordType != null && recordType.isAvailable())
SObj.put(DAL_BaseObject.RECORDTYPE_ID_FIELD, recordTypeId);
}
}
}
}
}
}