-
Notifications
You must be signed in to change notification settings - Fork 7
Expand file tree
/
Copy pathCustomMetadataTableController.cls
More file actions
133 lines (116 loc) · 5.63 KB
/
CustomMetadataTableController.cls
File metadata and controls
133 lines (116 loc) · 5.63 KB
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
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
//----------------------------------------------------------------------------------------------------//
// This file is part of the Custom Metadata Saver project, released under the MIT License. //
// See LICENSE file or go to https://github.com/jongpie/CustomMetadataSaver for full license details. //
//----------------------------------------------------------------------------------------------------//
public without sharing class CustomMetadataTableController {
//private static String BASE_URL = System.Url.getOrgDomainUrl().toExternalForm() + '/services/data/v62.0';
@AuraEnabled
public static String getSObjectApiName(SObject customMetadataRecord) {
System.debug(LoggingLevel.INFO, 'CustomMetadataTableController.getSObjectApiName(' + customMetadataRecord + ')');
return customMetadataRecord.getSObjectType().getDescribe().getName();
}
// @AuraEnabled(cacheable=true)
// public static List<PicklistOption> getPicklistOptions(String sobjectApiName, String fieldApiName) {
// System.debug(LoggingLevel.INFO, 'CustomMetadataTableController.getPicklistOptions(' + sobjectApiName + ',' + fieldApiName + ')');
// // Schema.PicklistEntry can't be returned by @AuraEnabled methods, so use an inner class PicklistOption instead
// Schema.SObjectType sobjectType = ((SObject) Type.forName(sobjectApiName).newInstance()).getSObjectType();
// List<Schema.PicklistEntry> schemaPicklistEntries = sobjectType.getDescribe().fields.getMap().get(fieldApiName).getDescribe().getPicklistValues();
// List<PicklistOption> picklistOptions = new List<PicklistOption>();
// for (Schema.PicklistEntry schemaPicklistEntry : schemaPicklistEntries) {
// PicklistOption picklistOption = new PicklistOption();
// picklistOption.label = schemaPicklistEntry.label;
// picklistOption.value = schemaPicklistEntry.value;
// picklistOptions.add(picklistOption);
// }
// return picklistOptions;
// }
@AuraEnabled
public static String deploy(List<SObject> customMetadataRecords) {
System.debug(LoggingLevel.INFO, 'CustomMetadataTableController.deploy(customMetadataRecords)==' + customMetadataRecords);
return CustomMetadataSaver.deploy(customMetadataRecords);
}
@AuraEnabled
public static String getDeploymentStatus(String deploymentJobId) {
System.debug(LoggingLevel.INFO, 'deploymentJobId==' + deploymentJobId);
//final String deploymentStatusUrl = BASE_URL + '/metadata/deployRequest/' + deploymentJobId + '?includeDetails=true';
HttpRequest request = new HttpRequest();
//request.setEndpoint(deploymentStatusUrl);
//request.setHeader('Authorization', 'Bearer ' + UserInfo.getSessionId());
request.setEndpoint('callout:AccessOrg/services/data/v62.0/metadata/deployRequest/' + deploymentJobId + '?includeDetails=true');
request.setHeader('Content-Type', 'application/json; charset=utf-8');
request.setMethod('GET');
//TODO: Deal with a permission issue on the named credential - try/catch and AuraHandledException here?
HttpResponse response = new Http().send(request);
System.debug('Deployment Response: ' + response.getBody());
//DeploymentStatusResponse deploymentStatusResponse = (DeploymentStatusResponse) JSON.deserialize(response.getBody(), DeploymentStatusResponse.class);
//System.debug(LoggingLevel.INFO, 'deploymentStatusResponse==' + deploymentStatusResponse);
return response.getBody();
}
// DTO for picklist options since Schema.PicklistEntry isn't supported for aura-enabled methods
// public class PicklistOption {
// @AuraEnabled
// public String label;
// @AuraEnabled
// public String value;
// }
// DTOs based on the REST API's response for deployments
// https://developer.salesforce.com/docs/atlas.en-us.api_meta.meta/api_meta/meta_rest_deploy_checkstatus.htm
public class DeploymentStatusResponse {
@AuraEnabled
public String id;
@AuraEnabled
public String url;
@AuraEnabled
public DeployResult deployResult;
}
public class DeployResult {
@AuraEnabled
public String status;
@AuraEnabled
public Integer numberComponentsDeployed;
@AuraEnabled
public Integer numberComponentsTotal;
@AuraEnabled
public Integer numberComponentErrors;
@AuraEnabled
public DeployResultDetails details;
}
public class DeployResultDetails {
@AuraEnabled
public List<ComponentResultDetail> allComponentMessages;
@AuraEnabled
public List<ComponentResultDetail> componentFailures;
@AuraEnabled
public List<ComponentResultDetail> componentSuccesses;
}
public class ComponentResultDetail {
@AuraEnabled
public String componentType;
@AuraEnabled
public String fullName;
@AuraEnabled
public String problem;
@AuraEnabled
public Boolean success;
@AuraEnabled
public Boolean warning;
@AuraEnabled
public Boolean created;
@AuraEnabled
public Boolean changed;
@AuraEnabled
public Boolean deleted;
@AuraEnabled
public Integer lineNumber;
@AuraEnabled
public Integer columnNumber;
@AuraEnabled
public Boolean requiresProductionTestRun;
@AuraEnabled
public Boolean knownPackagingProblem;
@AuraEnabled
public Boolean forPackageManifestFile;
@AuraEnabled
public String problemType;
}
}