@@ -423,7 +374,7 @@ See LICENSE file or go to https://github.com/jongpie/LightningComponents for ful
diff --git a/src/aura/simpleAdmin/simpleAdmin.cmp-meta.xml b/src/aura/simpleAdmin/simpleAdmin.cmp-meta.xml
index 7a568e3..25bab56 100644
--- a/src/aura/simpleAdmin/simpleAdmin.cmp-meta.xml
+++ b/src/aura/simpleAdmin/simpleAdmin.cmp-meta.xml
@@ -1,5 +1,5 @@
- 42.0
+ 43.0
simpleAdmin
diff --git a/src/aura/simpleAdmin/simpleAdminController.js b/src/aura/simpleAdmin/simpleAdminController.js
index 84664c2..999eae0 100644
--- a/src/aura/simpleAdmin/simpleAdminController.js
+++ b/src/aura/simpleAdmin/simpleAdminController.js
@@ -2,7 +2,7 @@
doInit : function(component, event, helper) {
helper.fetchEnvironmentMetadata(component, event);
helper.fetchCurrentUser(component, event);
- helper.fetchSObjectMetadata(component, event);
+ helper.fetchSobjectMetadata(component, event);
},
fetchFieldMetadata : function(component, event, helper) {
helper.fetchFieldMetadata(component, event);
@@ -17,19 +17,13 @@
fetchRecordTypeMetadata : function(component, event, helper) {
helper.fetchRecordTypeMetadata(component, event);
},
- viewListViewMetadata : function(component, event, helper) {
- component.set('v.showListViewModal', true);
- },
- fetchListViewMetadata : function(component, event, helper) {
- helper.fetchListViewMetadata(component, event);
- },
viewRecordTypeMetadata : function(component, event, helper) {
component.set('v.showRecordTypeModal', true);
},
- fetchSObjectMetadata : function(component, event, helper) {
+ fetchSobjectMetadata : function(component, event, helper) {
component.set('v.selectedField', null);
component.set('v.selectedListView', null);
component.set('v.selectedRecordType', null);
- helper.fetchSObjectMetadata(component, event);
+ helper.fetchSobjectMetadata(component, event);
}
})
\ No newline at end of file
diff --git a/src/aura/simpleAdmin/simpleAdminHelper.js b/src/aura/simpleAdmin/simpleAdminHelper.js
index b3d8216..2d004e8 100644
--- a/src/aura/simpleAdmin/simpleAdminHelper.js
+++ b/src/aura/simpleAdmin/simpleAdminHelper.js
@@ -17,12 +17,6 @@
component.set('v.fieldMetadata', response);
}));
},
- fetchListViewMetadata : function(component, event) {
- var listViewMetadataService = component.find('listViewMetadataService');
- listViewMetadataService.fetch($A.getCallback(function(error, response) {
- component.set('v.listViewMetadata', response);
- }));
- },
fetchQueueMetadata : function(component, event) {
console.log('simpl adm q');
var queueMetadataService = component.find('queueMetadataService');
@@ -38,7 +32,7 @@
component.set('v.recordTypeMetadata', response);
}));
},
- fetchSObjectMetadata : function(component, event) {
+ fetchSobjectMetadata : function(component, event) {
var sobjectMetadataService = component.find('sobjectMetadataService');
sobjectMetadataService.fetch($A.getCallback(function(error, response) {
component.set('v.sobjectMetadata', response);
diff --git a/src/aura/sobjectLabel/sobjectLabel.cmp b/src/aura/sobjectLabel/sobjectLabel.cmp
index 227a919..28bab6e 100644
--- a/src/aura/sobjectLabel/sobjectLabel.cmp
+++ b/src/aura/sobjectLabel/sobjectLabel.cmp
@@ -8,7 +8,7 @@ See LICENSE file or go to https://github.com/jongpie/LightningComponents for ful
-
-
+
+
\ No newline at end of file
diff --git a/src/aura/sobjectLabel/sobjectLabel.cmp-meta.xml b/src/aura/sobjectLabel/sobjectLabel.cmp-meta.xml
index c020327..1d722b7 100644
--- a/src/aura/sobjectLabel/sobjectLabel.cmp-meta.xml
+++ b/src/aura/sobjectLabel/sobjectLabel.cmp-meta.xml
@@ -1,5 +1,5 @@
- 42.0
+ 43.0
sobjectLabel
diff --git a/src/aura/sobjectMetadata/sobjectMetadata.cmp b/src/aura/sobjectMetadata/sobjectMetadata.cmp
index 989b48d..1901589 100644
--- a/src/aura/sobjectMetadata/sobjectMetadata.cmp
+++ b/src/aura/sobjectMetadata/sobjectMetadata.cmp
@@ -5,8 +5,8 @@ See LICENSE file or go to https://github.com/jongpie/LightningComponents for ful
-
-
+
+
diff --git a/src/aura/sobjectMetadata/sobjectMetadata.cmp-meta.xml b/src/aura/sobjectMetadata/sobjectMetadata.cmp-meta.xml
index 67ee0c8..6d0d118 100644
--- a/src/aura/sobjectMetadata/sobjectMetadata.cmp-meta.xml
+++ b/src/aura/sobjectMetadata/sobjectMetadata.cmp-meta.xml
@@ -1,5 +1,5 @@
- 42.0
+ 43.0
sobjectMetadata
diff --git a/src/aura/sobjectMetadata/sobjectMetadataController.js b/src/aura/sobjectMetadata/sobjectMetadataController.js
index 8970e36..b2eb35e 100644
--- a/src/aura/sobjectMetadata/sobjectMetadataController.js
+++ b/src/aura/sobjectMetadata/sobjectMetadataController.js
@@ -1,6 +1,6 @@
({
doInit : function(component, event, helper) {
- helper.fetchSObjectMetadata(component, event);
+ helper.fetchSobjectMetadata(component, event);
},
clearCachedMetadata : function(component, event, helper) {
component.set('v.sobjectMetadata', null);
diff --git a/src/aura/sobjectMetadata/sobjectMetadataHelper.js b/src/aura/sobjectMetadata/sobjectMetadataHelper.js
index 5b31ddf..ac1011b 100644
--- a/src/aura/sobjectMetadata/sobjectMetadataHelper.js
+++ b/src/aura/sobjectMetadata/sobjectMetadataHelper.js
@@ -1,5 +1,5 @@
({
- fetchSObjectMetadata : function(component, event) {
+ fetchSobjectMetadata : function(component, event) {
var sobjectMetadata = component.get('v.sobjectMetadata');
// If we already have the sobject metadata cached, use the cache
@@ -10,7 +10,7 @@
if(!sobjectApiName) return;
- var action = component.get('c.getSObjectMetadataByName');
+ var action = component.get('c.getSobjectMetadataByApiName');
action.setParams({
sobjectApiName : sobjectApiName
});
diff --git a/src/aura/toastNotification/toastNotification.cmp-meta.xml b/src/aura/toastNotification/toastNotification.cmp-meta.xml
index d70eb57..3d0d7f9 100644
--- a/src/aura/toastNotification/toastNotification.cmp-meta.xml
+++ b/src/aura/toastNotification/toastNotification.cmp-meta.xml
@@ -1,5 +1,5 @@
- 42.0
+ 43.0
Displays a messsage and optional details in a toast notification component
diff --git a/src/aura/toastNotificationEvent/toastNotificationEvent.evt-meta.xml b/src/aura/toastNotificationEvent/toastNotificationEvent.evt-meta.xml
index 5364c0b..f8f6679 100644
--- a/src/aura/toastNotificationEvent/toastNotificationEvent.evt-meta.xml
+++ b/src/aura/toastNotificationEvent/toastNotificationEvent.evt-meta.xml
@@ -1,5 +1,5 @@
- 42.0
+ 43.0
An event used to trigger displaying the toastNotification component
diff --git a/src/classes/ContextMetadata.cls b/src/classes/ContextMetadata.cls
new file mode 100644
index 0000000..4380301
--- /dev/null
+++ b/src/classes/ContextMetadata.cls
@@ -0,0 +1,31 @@
+/*************************************************************************************************
+* This file is part of the SimpleMetadata project, released under the MIT License. *
+* See LICENSE file or go to https://github.com/jongpie/SimpleMetadata for full license details. *
+*************************************************************************************************/
+global class ContextMetadata {
+
+ @AuraEnabled global final Boolean IsApexRest {get; private set;}
+ @AuraEnabled global final Boolean IsBatch {get; private set;}
+ @AuraEnabled global final Boolean IsExecuting {get; private set;}
+ @AuraEnabled global final Boolean IsFuture {get; private set;}
+ @AuraEnabled global final Boolean IsLightning {get; private set;}
+ @AuraEnabled global final Boolean IsLightningConsole {get; private set;}
+ @AuraEnabled global final Boolean IsQueueable {get; private set;}
+ @AuraEnabled global final Boolean IsSalesforce1 {get; private set;}
+ @AuraEnabled global final Boolean IsScheduled {get; private set;}
+ @AuraEnabled global final Boolean IsVisualforce {get; private set;}
+
+ global ContextMetadata() {
+ this.IsApexRest = RestContext.request != null;
+ this.IsBatch = System.isBatch();
+ this.IsExecuting = Trigger.isExecuting;
+ this.IsFuture = System.isFuture();
+ this.IsLightning = UserInfo.getUiThemeDisplayed() == 'Theme4d';
+ this.IsLightningConsole = UserInfo.getUiThemeDisplayed() == 'Theme4u';
+ this.IsQueueable = System.isQueueable();
+ this.IsSalesforce1 = UserInfo.getUiThemeDisplayed() == 'Theme4t';
+ this.IsScheduled = System.isScheduled();
+ this.IsVisualforce = ApexPages.currentPage() != null;
+ }
+
+}
\ No newline at end of file
diff --git a/src/classes/ListViewMetadata.cls-meta.xml b/src/classes/ContextMetadata.cls-meta.xml
similarity index 80%
rename from src/classes/ListViewMetadata.cls-meta.xml
rename to src/classes/ContextMetadata.cls-meta.xml
index f3bac1f..800e53c 100644
--- a/src/classes/ListViewMetadata.cls-meta.xml
+++ b/src/classes/ContextMetadata.cls-meta.xml
@@ -1,5 +1,5 @@
- 41.0
+ 43.0
Active
diff --git a/src/classes/ContextMetadata_Tests.cls b/src/classes/ContextMetadata_Tests.cls
new file mode 100644
index 0000000..78eb996
--- /dev/null
+++ b/src/classes/ContextMetadata_Tests.cls
@@ -0,0 +1,48 @@
+/*************************************************************************************************
+* This file is part of the SimpleMetadata project, released under the MIT License. *
+* See LICENSE file or go to https://github.com/jongpie/SimpleMetadata for full license details. *
+*************************************************************************************************/
+@isTest
+private class ContextMetadata_Tests {
+
+ @isTest
+ static void it_should_return_context_metadata() {
+ ContextMetadata contextMetadata = new ContextMetadata();
+ validateAttributesAreSet(contextMetadata);
+ validateCaseSentivityForJavascript(contextMetadata);
+ }
+
+ private static void validateAttributesAreSet(ContextMetadata contextMetadata) {
+ System.assertEquals(RestContext.request != null, contextMetadata.IsApexRest);
+ System.assertEquals(System.isBatch(), contextMetadata.IsBatch);
+ System.assertEquals(Trigger.isExecuting, contextMetadata.IsExecuting);
+ System.assertEquals(System.isFuture(), contextMetadata.IsFuture);
+ System.assertEquals(UserInfo.getUiThemeDisplayed() == 'Theme4d', contextMetadata.IsLightning);
+ System.assertEquals(UserInfo.getUiThemeDisplayed() == 'Theme4u', contextMetadata.IsLightningConsole);
+ System.assertEquals(System.isQueueable(), contextMetadata.IsQueueable);
+ System.assertEquals(UserInfo.getUiThemeDisplayed() == 'Theme4t', contextMetadata.IsSalesforce1);
+ System.assertEquals(System.isScheduled(), contextMetadata.IsScheduled);
+ System.assertEquals(ApexPages.currentPage() != null, contextMetadata.IsVisualforce);
+ }
+
+ private static void validateCaseSentivityForJavascript(ContextMetadata contextMetadata) {
+ // Validate that the attributes are named exactly as expected so that javascript can rely on them
+ String jsonContextMetadata = JSON.serialize(contextMetadata);
+ Map untypedContextMetadata = (Map)JSON.deserializeUntyped(jsonContextMetadata);
+
+ // One negative to confirm that the strings in our map are case sensitive
+ System.assert(untypedContextMetadata.containsKey('ISAPEXREST') == false);
+ // Now for the 'real' tests
+ System.assert(untypedContextMetadata.containsKey('IsApexRest'));
+ System.assert(untypedContextMetadata.containsKey('IsBatch'));
+ System.assert(untypedContextMetadata.containsKey('IsExecuting'));
+ System.assert(untypedContextMetadata.containsKey('IsFuture'));
+ System.assert(untypedContextMetadata.containsKey('IsLightning'));
+ System.assert(untypedContextMetadata.containsKey('IsLightningConsole'));
+ System.assert(untypedContextMetadata.containsKey('IsQueueable'));
+ System.assert(untypedContextMetadata.containsKey('IsSalesforce1'));
+ System.assert(untypedContextMetadata.containsKey('IsScheduled'));
+ System.assert(untypedContextMetadata.containsKey('IsVisualforce'));
+ }
+
+}
\ No newline at end of file
diff --git a/src/classes/SObjectMetadata_Tests.cls-meta.xml b/src/classes/ContextMetadata_Tests.cls-meta.xml
similarity index 80%
rename from src/classes/SObjectMetadata_Tests.cls-meta.xml
rename to src/classes/ContextMetadata_Tests.cls-meta.xml
index f3bac1f..800e53c 100644
--- a/src/classes/SObjectMetadata_Tests.cls-meta.xml
+++ b/src/classes/ContextMetadata_Tests.cls-meta.xml
@@ -1,5 +1,5 @@
- 41.0
+ 43.0
Active
diff --git a/src/classes/EnvironmentMetadata.cls b/src/classes/EnvironmentMetadata.cls
index b368bf8..db658e1 100644
--- a/src/classes/EnvironmentMetadata.cls
+++ b/src/classes/EnvironmentMetadata.cls
@@ -2,56 +2,56 @@
* This file is part of the SimpleMetadata project, released under the MIT License. *
* See LICENSE file or go to https://github.com/jongpie/SimpleMetadata for full license details. *
*************************************************************************************************/
-global virtual class EnvironmentMetadata {
+global class EnvironmentMetadata {
// Some info must be queried from the Organization object, so cache the results to limit query count to 1
- private static Organization organization;
+ private static final Organization ORGANIZATION;
static {
- organization = [SELECT Id, Name, InstanceName, NamespacePrefix, OrganizationType, IsSandbox FROM Organization LIMIT 1];
+ ORGANIZATION = [SELECT Id, Name, InstanceName, NamespacePrefix, OrganizationType, IsSandbox FROM Organization LIMIT 1];
}
- @AuraEnabled global final String baseUrl {get; private set;}
- @AuraEnabled global final String instanceName {get; private set;}
- @AuraEnabled global final Boolean isChatterEnabled {get; private set;}
- @AuraEnabled global final Boolean isKnowledgeEnabled {get; private set;}
- @AuraEnabled global final Boolean isMultiCurrencyEnabled {get; private set;}
- @AuraEnabled global final Boolean isPersonAccountEnabled {get; private set;}
- @AuraEnabled global final Boolean isProduction {get; private set;}
- @AuraEnabled global final Boolean isSandbox {get; private set;}
- @AuraEnabled global final Boolean isTerritoryManagementEnabled {get; private set;}
- @AuraEnabled global final String namespace {get; private set;}
- @AuraEnabled global final Id organizationId {get; private set;}
- @AuraEnabled global final String organizationName {get; private set;}
- @AuraEnabled global final String organizationType {get; private set;}
- @AuraEnabled global final List queueApiNames {get; private set;}
- @AuraEnabled global final List sobjectApiNames {get; private set;}
+ @AuraEnabled global final String BaseUrl {get; private set;}
+ @AuraEnabled global final String InstanceName {get; private set;}
+ @AuraEnabled global final Boolean IsChatterEnabled {get; private set;}
+ @AuraEnabled global final Boolean IsKnowledgeEnabled {get; private set;}
+ @AuraEnabled global final Boolean IsMultiCurrencyEnabled {get; private set;}
+ @AuraEnabled global final Boolean IsPersonAccountEnabled {get; private set;}
+ @AuraEnabled global final Boolean IsProduction {get; private set;}
+ @AuraEnabled global final Boolean IsSandbox {get; private set;}
+ @AuraEnabled global final Boolean IsTerritoryManagementEnabled {get; private set;}
+ @AuraEnabled global final String Namespace {get; private set;}
+ @AuraEnabled global final Id OrganizationId {get; private set;}
+ @AuraEnabled global final String OrganizationName {get; private set;}
+ @AuraEnabled global final String OrganizationType {get; private set;}
+ @AuraEnabled global final List QueueApiNames {get; private set;}
+ @AuraEnabled global final List SobjectApiNames {get; private set;}
global EnvironmentMetadata() {
- Map sobjectTypes = Schema.getGlobalDescribe();
+ Map sobjectTypes = Schema.getGlobalDescribe();
- this.baseUrl = Url.getSalesforceBaseUrl().toExternalForm();
- this.instanceName = organization.InstanceName;
- this.isChatterEnabled = sobjectTypes.containsKey('FeedItem');
- this.isKnowledgeEnabled = sobjectTypes.containsKey('KnowledgeArticle');
- this.isMultiCurrencyEnabled = UserInfo.isMultiCurrencyOrganization();
- this.isPersonAccountEnabled = sobjectTypes.get('Account').getDescribe().fields.getMap().containsKey('IsPersonAccount');
- this.isProduction = organization.IsSandbox == false;
- this.isSandbox = organization.IsSandbox;
- this.isTerritoryManagementEnabled = sobjectTypes.containsKey('Territory');
- this.namespace = organization.NamespacePrefix;
- this.organizationId = organization.Id;
- this.organizationName = organization.Name;
- this.organizationType = organization.OrganizationType;
- this.queueApiNames = QueueMetadata.getQueueApiNames();
- this.sobjectApiNames = this.getSObjectApiNames(sobjectTypes);
+ this.BaseUrl = Url.getSalesforceBaseUrl().toExternalForm();
+ this.InstanceName = ORGANIZATION.InstanceName;
+ this.IsChatterEnabled = sobjectTypes.containsKey('FeedItem');
+ this.IsKnowledgeEnabled = sobjectTypes.containsKey('KnowledgeArticle');
+ this.IsMultiCurrencyEnabled = UserInfo.isMultiCurrencyOrganization();
+ this.IsPersonAccountEnabled = sobjectTypes.get('Account').getDescribe().fields.getMap().containsKey('IsPersonAccount');
+ this.IsProduction = ORGANIZATION.IsSandbox == false;
+ this.IsSandbox = ORGANIZATION.IsSandbox;
+ this.IsTerritoryManagementEnabled = sobjectTypes.containsKey('Territory');
+ this.Namespace = ORGANIZATION.NamespacePrefix;
+ this.OrganizationId = ORGANIZATION.Id;
+ this.OrganizationName = ORGANIZATION.Name;
+ this.OrganizationType = ORGANIZATION.OrganizationType;
+ this.QueueApiNames = QueueMetadata.getQueueApiNames();
+ this.SobjectApiNames = this.getSobjectApiNames(sobjectTypes);
}
- private List getSObjectApiNames(Map sobjectTypes) {
+ private List getSobjectApiNames(Map sobjectTypes) {
// We could just use this.sobjectApiNames = new List(sobjectTypes.keySet());
// However, it returns the names in lowercase, which can cause problems with Javascript/Lightning since it's case-sensitive
List sobjectApiNames = new List();
- for(Schema.SObjectType sobjectType : sobjectTypes.values()) {
+ for(Schema.SobjectType sobjectType : sobjectTypes.values()) {
sobjectApiNames.add(String.valueOf(sobjectType));
}
sobjectApiNames.sort();
diff --git a/src/classes/EnvironmentMetadata.cls-meta.xml b/src/classes/EnvironmentMetadata.cls-meta.xml
index f3bac1f..800e53c 100644
--- a/src/classes/EnvironmentMetadata.cls-meta.xml
+++ b/src/classes/EnvironmentMetadata.cls-meta.xml
@@ -1,5 +1,5 @@
- 41.0
+ 43.0
Active
diff --git a/src/classes/EnvironmentMetadata_Tests.cls b/src/classes/EnvironmentMetadata_Tests.cls
index cac5d24..8894a6b 100644
--- a/src/classes/EnvironmentMetadata_Tests.cls
+++ b/src/classes/EnvironmentMetadata_Tests.cls
@@ -21,33 +21,35 @@ private class EnvironmentMetadata_Tests {
Test.startTest();
System.assertEquals(0, Limits.getQueries());
- // Only the first initialization should use a query, multiple initializations should use cached results
+ new EnvironmentMetadata();
+ Integer initialQueryCount = Limits.getQueries();
+ // Only the first initialization should use queries, multiple initializations should use cached results
for(Integer i = 0; i < 10; i++) {
new EnvironmentMetadata();
}
- System.assertEquals(1, Limits.getQueries());
+ System.assertEquals(initialQueryCount, Limits.getQueries());
Test.stopTest();
}
private static void validateAttributesAreSet(EnvironmentMetadata environmentMetadata) {
Organization organization = [SELECT Id, Name, InstanceName, NamespacePrefix, OrganizationType, IsSandbox FROM Organization LIMIT 1];
- Map sobjectTypes = Schema.getGlobalDescribe();
+ Map sobjectTypes = Schema.getGlobalDescribe();
- System.assertEquals(URL.getSalesforceBaseUrl().toExternalForm(), environmentMetadata.baseUrl);
- System.assertEquals(organization.InstanceName, environmentMetadata.instanceName);
- System.assertEquals(sobjectTypes.containsKey('FeedItem'), environmentMetadata.isChatterEnabled);
- System.assertEquals(sobjectTypes.containsKey('KnowledgeArticle'), environmentMetadata.isKnowledgeEnabled);
- System.assertEquals(UserInfo.isMultiCurrencyOrganization(), environmentMetadata.isMultiCurrencyEnabled);
- System.assertEquals(sobjectTypes.get('Account').getDescribe().fields.getMap().containsKey('IsPersonAccount'), environmentMetadata.isPersonAccountEnabled);
- System.assertEquals(organization.IsSandbox == false, environmentMetadata.isProduction);
- System.assertEquals(organization.IsSandbox, environmentMetadata.isSandbox);
- System.assertEquals(sobjectTypes.containsKey('Territory'), environmentMetadata.isTerritoryManagementEnabled);
- System.assertEquals(organization.NamespacePrefix, environmentMetadata.namespace);
- System.assertEquals(organization.Id, environmentMetadata.organizationId);
- System.assertEquals(organization.Name, environmentMetadata.organizationName);
- System.assertEquals(organization.OrganizationType, environmentMetadata.organizationType);
- //System.assert(environmentMetadata.sobjectTypeNames.containsAll(sobjectTypes.keySet()));
+ System.assertEquals(URL.getSalesforceBaseUrl().toExternalForm(), environmentMetadata.BaseUrl);
+ System.assertEquals(organization.InstanceName, environmentMetadata.InstanceName);
+ System.assertEquals(sobjectTypes.containsKey('FeedItem'), environmentMetadata.IsChatterEnabled);
+ System.assertEquals(sobjectTypes.containsKey('KnowledgeArticle'), environmentMetadata.IsKnowledgeEnabled);
+ System.assertEquals(UserInfo.isMultiCurrencyOrganization(), environmentMetadata.IsMultiCurrencyEnabled);
+ System.assertEquals(sobjectTypes.get('Account').getDescribe().fields.getMap().containsKey('IsPersonAccount'), environmentMetadata.IsPersonAccountEnabled);
+ System.assertEquals(organization.IsSandbox == false, environmentMetadata.IsProduction);
+ System.assertEquals(organization.IsSandbox, environmentMetadata.IsSandbox);
+ System.assertEquals(sobjectTypes.containsKey('Territory'), environmentMetadata.IsTerritoryManagementEnabled);
+ System.assertEquals(organization.NamespacePrefix, environmentMetadata.Namespace);
+ System.assertEquals(organization.Id, environmentMetadata.OrganizationId);
+ System.assertEquals(organization.Name, environmentMetadata.OrganizationName);
+ System.assertEquals(organization.OrganizationType, environmentMetadata.OrganizationType);
+ //System.assert(environmentMetadata.SobjectTypeNames.containsAll(sobjectTypes.keySet()));
}
private static void validateCaseSentivityForJavascript(EnvironmentMetadata environmentMetadata) {
@@ -58,20 +60,20 @@ private class EnvironmentMetadata_Tests {
// One negative to confirm that the strings in our map are case sensitive
System.assert(untypedEnvironmentMetadata.containsKey('BASEURL') == false);
// Now for the 'real' tests
- System.assert(untypedEnvironmentMetadata.containsKey('baseUrl'));
- System.assert(untypedEnvironmentMetadata.containsKey('instanceName'));
- System.assert(untypedEnvironmentMetadata.containsKey('isChatterEnabled'));
- System.assert(untypedEnvironmentMetadata.containsKey('isKnowledgeEnabled'));
- System.assert(untypedEnvironmentMetadata.containsKey('isMultiCurrencyEnabled'));
- System.assert(untypedEnvironmentMetadata.containsKey('isPersonAccountEnabled'));
- System.assert(untypedEnvironmentMetadata.containsKey('isProduction'));
- System.assert(untypedEnvironmentMetadata.containsKey('isSandbox'));
- System.assert(untypedEnvironmentMetadata.containsKey('isTerritoryManagementEnabled'));
- System.assert(untypedEnvironmentMetadata.containsKey('namespace'));
- System.assert(untypedEnvironmentMetadata.containsKey('organizationId'));
- System.assert(untypedEnvironmentMetadata.containsKey('organizationName'));
- System.assert(untypedEnvironmentMetadata.containsKey('organizationType'));
- System.assert(untypedEnvironmentMetadata.containsKey('sobjectApiNames'));
+ System.assert(untypedEnvironmentMetadata.containsKey('BaseUrl'));
+ System.assert(untypedEnvironmentMetadata.containsKey('InstanceName'));
+ System.assert(untypedEnvironmentMetadata.containsKey('IsChatterEnabled'));
+ System.assert(untypedEnvironmentMetadata.containsKey('IsKnowledgeEnabled'));
+ System.assert(untypedEnvironmentMetadata.containsKey('IsMultiCurrencyEnabled'));
+ System.assert(untypedEnvironmentMetadata.containsKey('IsPersonAccountEnabled'));
+ System.assert(untypedEnvironmentMetadata.containsKey('IsProduction'));
+ System.assert(untypedEnvironmentMetadata.containsKey('IsSandbox'));
+ System.assert(untypedEnvironmentMetadata.containsKey('IsTerritoryManagementEnabled'));
+ System.assert(untypedEnvironmentMetadata.containsKey('Namespace'));
+ System.assert(untypedEnvironmentMetadata.containsKey('OrganizationId'));
+ System.assert(untypedEnvironmentMetadata.containsKey('OrganizationName'));
+ System.assert(untypedEnvironmentMetadata.containsKey('OrganizationType'));
+ System.assert(untypedEnvironmentMetadata.containsKey('SobjectApiNames'));
}
}
\ No newline at end of file
diff --git a/src/classes/EnvironmentMetadata_Tests.cls-meta.xml b/src/classes/EnvironmentMetadata_Tests.cls-meta.xml
index f3bac1f..800e53c 100644
--- a/src/classes/EnvironmentMetadata_Tests.cls-meta.xml
+++ b/src/classes/EnvironmentMetadata_Tests.cls-meta.xml
@@ -1,5 +1,5 @@
- 41.0
+ 43.0
Active
diff --git a/src/classes/FieldMetadata.cls b/src/classes/FieldMetadata.cls
index 9a6bea7..baac404 100644
--- a/src/classes/FieldMetadata.cls
+++ b/src/classes/FieldMetadata.cls
@@ -2,40 +2,40 @@
* This file is part of the SimpleMetadata project, released under the MIT License. *
* See LICENSE file or go to https://github.com/jongpie/SimpleMetadata for full license details. *
*************************************************************************************************/
-global virtual class FieldMetadata {
+global class FieldMetadata {
- @AuraEnabled global final String apiName {get; private set;}
- @AuraEnabled global final Integer byteLength {get; private set;}
- @AuraEnabled global final Object defaultValue {get; private set;}
- @AuraEnabled global final Integer digits {get; private set;}
- @AuraEnabled global final String displayType {get; private set;}
- @AuraEnabled global final String inlineHelpText {get; private set;}
- @AuraEnabled global final Boolean isAccessible {get; private set;}
- @AuraEnabled global final Boolean isAutoNumber {get; private set;}
- @AuraEnabled global final Boolean isCalculated {get; private set;}
- @AuraEnabled global final Boolean isCaseSensitive {get; private set;}
- @AuraEnabled global final Boolean isCreateable {get; private set;}
- @AuraEnabled global final Boolean isCustom {get; private set;}
- @AuraEnabled global final Boolean isDefaultedOnCreate {get; private set;}
- @AuraEnabled global final Boolean isFilterable {get; private set;}
- @AuraEnabled global final Boolean isGroupable {get; private set;}
- @AuraEnabled global final Boolean isNameField {get; private set;}
- @AuraEnabled global final Boolean isNillable {get; private set;}
- @AuraEnabled global final Boolean isRequired {get; private set;}
- @AuraEnabled global final Boolean isSortable {get; private set;}
- @AuraEnabled global final Boolean isUpdateable {get; private set;}
- @AuraEnabled global final String label {get; private set;}
- @AuraEnabled global final String localApiName {get; private set;}
- @AuraEnabled global final Integer maxLength {get; private set;}
- @AuraEnabled global final String namespace {get; private set;}
- @AuraEnabled global final List picklistOptions {get; private set;}
- @AuraEnabled global final Integer precision {get; private set;}
- @AuraEnabled global final String relationshipName {get; private set;}
- @AuraEnabled global final Integer relationshipOrder {get; private set;}
- @AuraEnabled global final List relationshipReferences {get; private set;} // TODO consider changing to string[] of names instead
- @AuraEnabled global final Integer scale {get; private set;}
- @AuraEnabled global final String soapType {get; private set;}
- @AuraEnabled global final String sobjectApiName {get; private set;}
+ @AuraEnabled global final String ApiName {get; private set;}
+ @AuraEnabled global final Integer ByteLength {get; private set;}
+ @AuraEnabled global final Object DefaultValue {get; private set;}
+ @AuraEnabled global final Integer Digits {get; private set;}
+ @AuraEnabled global final String DisplayType {get; private set;}
+ @AuraEnabled global final String InlineHelpText {get; private set;}
+ @AuraEnabled global final Boolean IsAccessible {get; private set;}
+ @AuraEnabled global final Boolean IsAutoNumber {get; private set;}
+ @AuraEnabled global final Boolean IsCalculated {get; private set;}
+ @AuraEnabled global final Boolean IsCaseSensitive {get; private set;}
+ @AuraEnabled global final Boolean IsCreateable {get; private set;}
+ @AuraEnabled global final Boolean IsCustom {get; private set;}
+ @AuraEnabled global final Boolean IsDefaultedOnCreate {get; private set;}
+ @AuraEnabled global final Boolean IsFilterable {get; private set;}
+ @AuraEnabled global final Boolean IsGroupable {get; private set;}
+ @AuraEnabled global final Boolean IsNameField {get; private set;}
+ @AuraEnabled global final Boolean IsNillable {get; private set;}
+ @AuraEnabled global final Boolean IsNamePointing {get; private set;}
+ @AuraEnabled global final Boolean IsRequired {get; private set;}
+ @AuraEnabled global final Boolean IsSortable {get; private set;}
+ @AuraEnabled global final Boolean IsUpdateable {get; private set;}
+ @AuraEnabled global final String Label {get; private set;}
+ @AuraEnabled global final String LocalApiName {get; private set;}
+ @AuraEnabled global final Integer MaxLength {get; private set;}
+ @AuraEnabled global final String Namespace {get; private set;}
+ @AuraEnabled global final List PicklistOptions {get; private set;}
+ @AuraEnabled global final Integer Precision {get; private set;}
+ @AuraEnabled global final String RelationshipApiName {get; private set;}
+ @AuraEnabled global final Integer RelationshipOrder {get; private set;}
+ @AuraEnabled global final List RelationshipReferences {get; private set;}
+ @AuraEnabled global final Integer Scale {get; private set;}
+ @AuraEnabled global final String SobjectApiName {get; private set;}
global FieldMetadata(String sobjectApiName, String fieldApiName) {
this(
@@ -44,42 +44,42 @@ global virtual class FieldMetadata {
);
}
- global FieldMetadata(Schema.SObjectType sobjectType, Schema.SObjectField sobjectField) {
- Schema.DescribeSObjectResult sobjectDescribe = sobjectType.getDescribe();
+ global FieldMetadata(Schema.SobjectType sobjectType, Schema.SobjectField sobjectField) {
+ Schema.DescribeSobjectResult sobjectDescribe = sobjectType.getDescribe();
Schema.DescribeFieldResult fieldDescribe = sobjectField.getDescribe();
- this.apiName = String.valueOf(sobjectField);
- this.byteLength = fieldDescribe.getByteLength();
- this.defaultValue = fieldDescribe.getDefaultValue();
- this.digits = fieldDescribe.getDigits();
- this.displayType = fieldDescribe.getType().name();
- this.inlineHelpText = fieldDescribe.getInlineHelpText();
- this.isAccessible = fieldDescribe.isAccessible();
- this.isAutoNumber = fieldDescribe.isAutoNumber();
- this.isCalculated = fieldDescribe.isCalculated();
- this.isCaseSensitive = fieldDescribe.isCaseSensitive();
- this.isCreateable = fieldDescribe.isCreateable();
- this.isCustom = fieldDescribe.isCustom();
- this.isDefaultedOnCreate = fieldDescribe.isDefaultedOnCreate();
- this.isFilterable = fieldDescribe.isFilterable();
- this.isGroupable = fieldDescribe.isGroupable();
- this.isNameField = fieldDescribe.isNameField();
- this.isNillable = fieldDescribe.isNillable();
- this.isRequired = fieldDescribe.isNillable() == false && fieldDescribe.isCreateable(); // If a field is NOT nillable, then it's required
- this.isSortable = fieldDescribe.isSortable();
- this.isUpdateable = fieldDescribe.isUpdateable();
- this.label = fieldDescribe.getLabel();
- this.localApiName = fieldDescribe.getLocalName();
- this.maxLength = fieldDescribe.getLength();
- this.namespace = this.getNamespace();
- this.picklistOptions = this.getPicklistOptions(fieldDescribe);
- this.precision = fieldDescribe.getPrecision();
- this.relationshipName = fieldDescribe.getRelationshipName();
- this.relationshipOrder = fieldDescribe.getRelationshipOrder();
- this.relationshipReferences = this.getRelationshipReferences(fieldDescribe);
- this.scale = fieldDescribe.getScale();
- this.soapType = fieldDescribe.getSOAPType().name();
- this.sobjectApiName = String.valueOf(sobjectType);
+ this.ApiName = String.valueOf(sobjectField);
+ this.ByteLength = fieldDescribe.getByteLength();
+ this.DefaultValue = fieldDescribe.getDefaultValue();
+ this.Digits = fieldDescribe.getDigits();
+ this.DisplayType = fieldDescribe.getType().name();
+ this.InlineHelpText = fieldDescribe.getInlineHelpText();
+ this.IsAccessible = fieldDescribe.isAccessible();
+ this.IsAutoNumber = fieldDescribe.isAutoNumber();
+ this.IsCalculated = fieldDescribe.isCalculated();
+ this.IsCaseSensitive = fieldDescribe.isCaseSensitive();
+ this.IsCreateable = fieldDescribe.isCreateable();
+ this.IsCustom = fieldDescribe.isCustom();
+ this.IsDefaultedOnCreate = fieldDescribe.isDefaultedOnCreate();
+ this.IsFilterable = fieldDescribe.isFilterable();
+ this.IsGroupable = fieldDescribe.isGroupable();
+ this.IsNameField = fieldDescribe.isNameField();
+ this.IsNillable = fieldDescribe.isNillable();
+ this.IsNamePointing = fieldDescribe.isNamePointing();
+ this.IsRequired = fieldDescribe.isNillable() == false && fieldDescribe.isCreateable(); // If a field is NOT nillable, then it's required
+ this.IsSortable = fieldDescribe.isSortable();
+ this.IsUpdateable = fieldDescribe.isUpdateable();
+ this.Label = fieldDescribe.getLabel();
+ this.LocalApiName = fieldDescribe.getLocalName();
+ this.MaxLength = fieldDescribe.getLength();
+ this.Namespace = this.getNamespace();
+ this.PicklistOptions = this.getPicklistOptions(fieldDescribe);
+ this.Precision = fieldDescribe.getPrecision();
+ this.RelationshipApiName = fieldDescribe.getRelationshipName();
+ this.RelationshipOrder = fieldDescribe.getRelationshipOrder();
+ this.RelationshipReferences = this.getRelationshipReferences(fieldDescribe);
+ this.Scale = fieldDescribe.getScale();
+ this.SobjectApiName = String.valueOf(sobjectType);
}
private String getNamespace() {
@@ -99,30 +99,30 @@ global virtual class FieldMetadata {
return picklistOptions;
}
- private List getRelationshipReferences(Schema.DescribeFieldResult fieldDescribe) {
- List relationshipReferences = new List();
- for(Schema.SObjectType sobjectType : fieldDescribe.getReferenceTo()) {
- relationshipReferences.add(new SObjectMetadata(sobjectType));
+ private List getRelationshipReferences(Schema.DescribeFieldResult fieldDescribe) {
+ List relationshipReferences = new List();
+ for(Schema.SobjectType sobjectType : fieldDescribe.getReferenceTo()) {
+ relationshipReferences.add(new SobjectMetadata(sobjectType));
}
return relationshipReferences;
}
- global virtual class PicklistEntryMetadata {
+ global class PicklistEntryMetadata {
- @AuraEnabled global final Boolean isDefaultValue {get; private set;}
- @AuraEnabled global final String label {get; private set;}
- @AuraEnabled global final String value {get; private set;}
+ @AuraEnabled global final Boolean IsDefaultValue {get; private set;}
+ @AuraEnabled global final String Label {get; private set;}
+ @AuraEnabled global final String Value {get; private set;}
global PicklistEntryMetadata() {
- this.isDefaultValue = false;
- this.label = '--None--';
- this.value = '';
+ this.IsDefaultValue = false;
+ this.Label = '';
+ this.Value = '';
}
global PicklistEntryMetadata(Schema.PicklistEntry picklistEntry) {
- this.isDefaultValue = picklistEntry.isDefaultValue();
- this.label = picklistEntry.getLabel();
- this.value = picklistEntry.getValue();
+ this.IsDefaultValue = picklistEntry.isDefaultValue();
+ this.Label = picklistEntry.getLabel();
+ this.Value = picklistEntry.getValue();
}
}
diff --git a/src/classes/FieldMetadata.cls-meta.xml b/src/classes/FieldMetadata.cls-meta.xml
index f3bac1f..800e53c 100644
--- a/src/classes/FieldMetadata.cls-meta.xml
+++ b/src/classes/FieldMetadata.cls-meta.xml
@@ -1,5 +1,5 @@
- 41.0
+ 43.0
Active
diff --git a/src/classes/FieldMetadata_Tests.cls b/src/classes/FieldMetadata_Tests.cls
index 990bd67..ebead4f 100644
--- a/src/classes/FieldMetadata_Tests.cls
+++ b/src/classes/FieldMetadata_Tests.cls
@@ -21,12 +21,12 @@ private class FieldMetadata_Tests {
@isTest
static void it_should_return_metadata_for_sobject_type_token_and_field_token() {
- SObjectType accountSObjectType = Account.SObjectType;
- SObjectField accountNameField = Account.Name;
+ SobjectType accountSobjectType = Account.SobjectType;
+ SobjectField accountNameField = Account.Name;
Test.startTest();
- FieldMetadata accountFieldMetadata = new FieldMetadata(accountSObjectType, accountNameField);
+ FieldMetadata accountFieldMetadata = new FieldMetadata(accountSobjectType, accountNameField);
validateAttributesAreSet(String.valueOf(accountNameField), accountFieldMetadata);
validateCaseSentivityForJavascript(accountFieldMetadata);
@@ -35,11 +35,11 @@ private class FieldMetadata_Tests {
@isTest
static void it_should_return_metadata_for_account_parentid_lookup_field_token() {
- SObjectField parentIdField = Account.ParentId;
+ SobjectField parentIdField = Account.ParentId;
Test.startTest();
- FieldMetadata accountFieldMetadata = new FieldMetadata(Account.SObjectType, parentIdField);
+ FieldMetadata accountFieldMetadata = new FieldMetadata(Account.SobjectType, parentIdField);
validateAttributesAreSet(String.valueOf(parentIdField), accountFieldMetadata);
validateCaseSentivityForJavascript(accountFieldMetadata);
@@ -48,11 +48,11 @@ private class FieldMetadata_Tests {
@isTest
static void it_should_return_metadata_for_account_type_picklist_field_token() {
- SObjectField typeField = Account.Type;
+ SobjectField typeField = Account.Type;
Test.startTest();
- FieldMetadata accountFieldMetadata = new FieldMetadata(Account.SObjectType, typeField);
+ FieldMetadata accountFieldMetadata = new FieldMetadata(Account.SobjectType, typeField);
validateAttributesAreSet(String.valueOf(typeField), accountFieldMetadata);
validateCaseSentivityForJavascript(accountFieldMetadata);
@@ -61,41 +61,39 @@ private class FieldMetadata_Tests {
private static void validateAttributesAreSet(String fieldName, FieldMetadata fieldMetadata) {
String sobjectName = 'Account';
- DescribeFieldResult fieldDescribe = Schema.SObjectType.Account.fields.getMap().get(fieldName).getDescribe();
-
- System.assertEquals(fieldDescribe.getName(), fieldMetadata.apiName);
- System.assertEquals(fieldDescribe.getByteLength(), fieldMetadata.byteLength);
- System.assertEquals(fieldDescribe.getDefaultValue(), fieldMetadata.defaultValue);
- System.assertEquals(fieldDescribe.getDigits(), fieldMetadata.digits);
- System.assertEquals(fieldDescribe.getType().name(), fieldMetadata.displayType);
- System.assertEquals(fieldDescribe.getInlineHelpText(), fieldMetadata.inlineHelpText);
- System.assertEquals(fieldDescribe.isAccessible(), fieldMetadata.isAccessible);
- System.assertEquals(fieldDescribe.isAutoNumber(), fieldMetadata.isAutoNumber);
- System.assertEquals(fieldDescribe.isCalculated(), fieldMetadata.isCalculated);
- System.assertEquals(fieldDescribe.isCaseSensitive(), fieldMetadata.isCaseSensitive);
- System.assertEquals(fieldDescribe.isCreateable(), fieldMetadata.isCreateable);
- System.assertEquals(fieldDescribe.isCustom(), fieldMetadata.isCustom);
- System.assertEquals(fieldDescribe.isDefaultedOnCreate(), fieldMetadata.isDefaultedOnCreate);
- System.assertEquals(fieldDescribe.isFilterable(), fieldMetadata.isFilterable);
- System.assertEquals(fieldDescribe.isGroupable(), fieldMetadata.isGroupable);
- System.assertEquals(fieldDescribe.isNameField(), fieldMetadata.isNameField);
- System.assertEquals(fieldDescribe.isNillable(), fieldMetadata.isNillable);
- System.assertEquals(fieldDescribe.isNillable() == false && fieldDescribe.isCreateable(), fieldMetadata.isRequired);
- System.assertEquals(fieldDescribe.isSortable(), fieldMetadata.isSortable);
- System.assertEquals(fieldDescribe.isUpdateable(), fieldMetadata.isUpdateable);
- System.assertEquals(fieldDescribe.getLabel(), fieldMetadata.label);
- System.assertEquals(fieldDescribe.getLocalName(), fieldMetadata.localApiName);
- System.assertEquals(fieldDescribe.getLength(), fieldMetadata.maxLength);
+ DescribeFieldResult fieldDescribe = Schema.SobjectType.Account.fields.getMap().get(fieldName).getDescribe();
+
+ System.assertEquals(fieldDescribe.getName(), fieldMetadata.ApiName);
+ System.assertEquals(fieldDescribe.getByteLength(), fieldMetadata.ByteLength);
+ System.assertEquals(fieldDescribe.getDefaultValue(), fieldMetadata.DefaultValue);
+ System.assertEquals(fieldDescribe.getDigits(), fieldMetadata.Digits);
+ System.assertEquals(fieldDescribe.getType().name(), fieldMetadata.DisplayType);
+ System.assertEquals(fieldDescribe.getInlineHelpText(), fieldMetadata.InlineHelpText);
+ System.assertEquals(fieldDescribe.isAccessible(), fieldMetadata.IsAccessible);
+ System.assertEquals(fieldDescribe.isAutoNumber(), fieldMetadata.IsAutoNumber);
+ System.assertEquals(fieldDescribe.isCalculated(), fieldMetadata.IsCalculated);
+ System.assertEquals(fieldDescribe.isCaseSensitive(), fieldMetadata.IsCaseSensitive);
+ System.assertEquals(fieldDescribe.isCreateable(), fieldMetadata.IsCreateable);
+ System.assertEquals(fieldDescribe.isCustom(), fieldMetadata.IsCustom);
+ System.assertEquals(fieldDescribe.isDefaultedOnCreate(), fieldMetadata.IsDefaultedOnCreate);
+ System.assertEquals(fieldDescribe.isFilterable(), fieldMetadata.IsFilterable);
+ System.assertEquals(fieldDescribe.isGroupable(), fieldMetadata.IsGroupable);
+ System.assertEquals(fieldDescribe.isNameField(), fieldMetadata.IsNameField);
+ System.assertEquals(fieldDescribe.isNillable(), fieldMetadata.IsNillable);
+ System.assertEquals(fieldDescribe.isNillable() == false && fieldDescribe.isCreateable(), fieldMetadata.IsRequired);
+ System.assertEquals(fieldDescribe.isSortable(), fieldMetadata.IsSortable);
+ System.assertEquals(fieldDescribe.isUpdateable(), fieldMetadata.IsUpdateable);
+ System.assertEquals(fieldDescribe.getLabel(), fieldMetadata.Label);
+ System.assertEquals(fieldDescribe.getLocalName(), fieldMetadata.LocalApiName);
+ System.assertEquals(fieldDescribe.getLength(), fieldMetadata.MaxLength);
//System.assertEquals(this.getNamespace(), fieldMetadata.namespace);
//System.assertEquals(this.getPicklistOptions(fieldDescribe), fieldMetadata.picklistOptions);
- System.assertEquals(fieldDescribe.getPrecision(), fieldMetadata.precision);
- System.assertEquals(fieldDescribe.getRelationshipName(), fieldMetadata.relationshipName);
- System.assertEquals(fieldDescribe.getRelationshipOrder(), fieldMetadata.relationshipOrder);
- //System.assertEquals( this.getRelationshipReferences(fieldDescribe), fieldMetadata.relationshipReferences);
- System.assertEquals(fieldDescribe.getScale(), fieldMetadata.scale);
- System.assertEquals(fieldDescribe.getScale(), fieldMetadata.scale);
- System.assertEquals(fieldDescribe.getSOAPType().name(), fieldMetadata.soapType);
- System.assertEquals(sobjectName, fieldMetadata.sobjectApiName);
+ System.assertEquals(fieldDescribe.getPrecision(), fieldMetadata.Precision);
+ System.assertEquals(fieldDescribe.getRelationshipName(), fieldMetadata.RelationshipApiName);
+ System.assertEquals(fieldDescribe.getRelationshipOrder(), fieldMetadata.RelationshipOrder);
+ //System.assertEquals( this.getRelationshipReferences(fieldDescribe), fieldMetadata.RelationshipReferences);
+ System.assertEquals(fieldDescribe.getScale(), fieldMetadata.Scale);
+ System.assertEquals(sobjectName, fieldMetadata.SobjectApiName);
}
private static void validateCaseSentivityForJavascript(FieldMetadata fieldMetadata) {
@@ -106,38 +104,37 @@ private class FieldMetadata_Tests {
// One negative to confirm that the strings in our map are case sensitive
System.assert(untypedFieldMetadata.containsKey('APINAME') == false);
// Now for the 'real' tests
- System.assert(untypedFieldMetadata.containsKey('apiName'));
- System.assert(untypedFieldMetadata.containsKey('byteLength'));
- System.assert(untypedFieldMetadata.containsKey('defaultValue'));
- System.assert(untypedFieldMetadata.containsKey('digits'));
- System.assert(untypedFieldMetadata.containsKey('displayType'));
- System.assert(untypedFieldMetadata.containsKey('inlineHelpText'));
- System.assert(untypedFieldMetadata.containsKey('isAccessible'));
- System.assert(untypedFieldMetadata.containsKey('isAutoNumber'));
- System.assert(untypedFieldMetadata.containsKey('isCalculated'));
- System.assert(untypedFieldMetadata.containsKey('isCaseSensitive'));
- System.assert(untypedFieldMetadata.containsKey('isCreateable'));
- System.assert(untypedFieldMetadata.containsKey('isCustom'));
- System.assert(untypedFieldMetadata.containsKey('isDefaultedOnCreate'));
- System.assert(untypedFieldMetadata.containsKey('isFilterable'));
- System.assert(untypedFieldMetadata.containsKey('isGroupable'));
- System.assert(untypedFieldMetadata.containsKey('isNameField'));
- System.assert(untypedFieldMetadata.containsKey('isNillable'));
- System.assert(untypedFieldMetadata.containsKey('isRequired'));
- System.assert(untypedFieldMetadata.containsKey('isSortable'));
- System.assert(untypedFieldMetadata.containsKey('isUpdateable'));
- System.assert(untypedFieldMetadata.containsKey('label'));
- System.assert(untypedFieldMetadata.containsKey('localApiName'));
- System.assert(untypedFieldMetadata.containsKey('maxLength'));
- System.assert(untypedFieldMetadata.containsKey('namespace'));
- System.assert(untypedFieldMetadata.containsKey('picklistOptions'));
- System.assert(untypedFieldMetadata.containsKey('precision'));
- System.assert(untypedFieldMetadata.containsKey('relationshipName'));
- System.assert(untypedFieldMetadata.containsKey('relationshipOrder'));
- System.assert(untypedFieldMetadata.containsKey('relationshipReferences'));
- System.assert(untypedFieldMetadata.containsKey('scale'));
- System.assert(untypedFieldMetadata.containsKey('soapType'));
- System.assert(untypedFieldMetadata.containsKey('sobjectApiName'));
+ System.assert(untypedFieldMetadata.containsKey('ApiName'));
+ System.assert(untypedFieldMetadata.containsKey('ByteLength'));
+ System.assert(untypedFieldMetadata.containsKey('DefaultValue'));
+ System.assert(untypedFieldMetadata.containsKey('Digits'));
+ System.assert(untypedFieldMetadata.containsKey('DisplayType'));
+ System.assert(untypedFieldMetadata.containsKey('InlineHelpText'));
+ System.assert(untypedFieldMetadata.containsKey('IsAccessible'));
+ System.assert(untypedFieldMetadata.containsKey('IsAutoNumber'));
+ System.assert(untypedFieldMetadata.containsKey('IsCalculated'));
+ System.assert(untypedFieldMetadata.containsKey('IsCaseSensitive'));
+ System.assert(untypedFieldMetadata.containsKey('IsCreateable'));
+ System.assert(untypedFieldMetadata.containsKey('IsCustom'));
+ System.assert(untypedFieldMetadata.containsKey('IsDefaultedOnCreate'));
+ System.assert(untypedFieldMetadata.containsKey('IsFilterable'));
+ System.assert(untypedFieldMetadata.containsKey('IsGroupable'));
+ System.assert(untypedFieldMetadata.containsKey('IsNameField'));
+ System.assert(untypedFieldMetadata.containsKey('IsNillable'));
+ System.assert(untypedFieldMetadata.containsKey('IsRequired'));
+ System.assert(untypedFieldMetadata.containsKey('IsSortable'));
+ System.assert(untypedFieldMetadata.containsKey('IsUpdateable'));
+ System.assert(untypedFieldMetadata.containsKey('Label'));
+ System.assert(untypedFieldMetadata.containsKey('LocalApiName'));
+ System.assert(untypedFieldMetadata.containsKey('MaxLength'));
+ System.assert(untypedFieldMetadata.containsKey('Namespace'));
+ System.assert(untypedFieldMetadata.containsKey('PicklistOptions'));
+ System.assert(untypedFieldMetadata.containsKey('Precision'));
+ System.assert(untypedFieldMetadata.containsKey('RelationshipApiName'));
+ System.assert(untypedFieldMetadata.containsKey('RelationshipOrder'));
+ System.assert(untypedFieldMetadata.containsKey('RelationshipReferences'));
+ System.assert(untypedFieldMetadata.containsKey('Scale'));
+ System.assert(untypedFieldMetadata.containsKey('SobjectApiName'));
}
}
\ No newline at end of file
diff --git a/src/classes/FieldMetadata_Tests.cls-meta.xml b/src/classes/FieldMetadata_Tests.cls-meta.xml
index f3bac1f..800e53c 100644
--- a/src/classes/FieldMetadata_Tests.cls-meta.xml
+++ b/src/classes/FieldMetadata_Tests.cls-meta.xml
@@ -1,5 +1,5 @@
- 41.0
+ 43.0
Active
diff --git a/src/classes/FieldSetMetadata.cls b/src/classes/FieldSetMetadata.cls
index c6afec4..fc666d8 100644
--- a/src/classes/FieldSetMetadata.cls
+++ b/src/classes/FieldSetMetadata.cls
@@ -2,97 +2,101 @@
* This file is part of the SimpleMetadata project, released under the MIT License. *
* See LICENSE file or go to https://github.com/jongpie/SimpleMetadata for full license details. *
*************************************************************************************************/
-global virtual class FieldSetMetadata {
+global class FieldSetMetadata {
- @AuraEnabled global final String apiName {get; private set;}
- @AuraEnabled global final String description {get; private set;}
- @AuraEnabled global final List fieldSetMembers {get; private set;}
- @AuraEnabled global final String label {get; private set;}
- @AuraEnabled global final String localApiName {get; private set;}
- @AuraEnabled global final String namespace {get; private set;}
- @AuraEnabled global final String sobjectApiName {get; private set;}
+ @AuraEnabled global final String ApiName {get; private set;}
+ @AuraEnabled global final String Description {get; private set;}
+ @AuraEnabled global final List FieldSetMembers {get; private set;}
+ @AuraEnabled global final String Label {get; private set;}
+ @AuraEnabled global final String LocalApiName {get; private set;}
+ @AuraEnabled global final String Namespace {get; private set;}
+ @AuraEnabled global final String SobjectApiName {get; private set;}
global FieldSetMetadata(String sobjectApiName, String fieldSetApiName) {
this(Schema.getGlobalDescribe().get(sobjectApiName).getDescribe().fieldSets.getMap().get(fieldSetApiName));
}
global FieldSetMetadata(Schema.FieldSet fieldSet) {
- // SObject name & field name are used to set other values, so set them first
- this.sobjectApiName = String.valueOf(fieldSet.getSObjectType());
- this.apiName = (fieldSet.getNamespace() == null ? '' : fieldSet.getNamespace() + '__') + fieldSet.getName();
-
- this.description = fieldSet.getDescription();
- this.fieldSetMembers = this.getFieldSetMembers(fieldSet);
- this.label = fieldSet.getLabel();
- this.localApiName = this.getLocalApiName();
- this.namespace = fieldSet.getNamespace();
+ this.ApiName = this.getApiName(fieldSet);
+ this.Description = fieldSet.getDescription();
+ this.FieldSetMembers = this.getFieldSetMembers(fieldSet);
+ this.Label = fieldSet.getLabel();
+ this.LocalApiName = fieldSet.getName();
+ this.Namespace = fieldSet.getNamespace();
+ this.SobjectApiName = String.valueOf(fieldSet.getSobjectType());
+ }
+
+ private String getApiName(Schema.FieldSet fieldSet) {
+ String namespace = fieldSet.getNamespace() == null ? '' : fieldSet.getNamespace() + '__';
+ return namespace + fieldSet.getName();
}
private List getFieldSetMembers(Schema.FieldSet fieldSet) {
List fieldSetMembers = new List();
for(Schema.FieldSetMember fieldSetMember : fieldSet.getFields()) {
- FieldSetMemberMetadata fieldSetMemberMetadata = new FieldSetMemberMetadata(this.sobjectApiName, fieldSetMember);
+ FieldSetMemberMetadata fieldSetMemberMetadata = new FieldSetMemberMetadata(fieldSet.getSobjectType(), fieldSetMember);
fieldSetMembers.add(fieldSetMemberMetadata);
}
+ fieldSetMembers.sort();
return fieldSetMembers;
}
- private String getLocalApiName() {
- Integer localNameIndex = this.apiName.replace('__c', '').indexOf('__');
- // Add to to the localNameIndex to compensate for the '__' part of the namespace
- return localNameIndex < 0 ? null : this.apiName.substring(localNameIndex + 2, this.apiName.length());
- }
+ global class FieldSetMemberMetadata implements Comparable {
+
+ @AuraEnabled global final String DisplayType {get; private set;}
+ @AuraEnabled global final FieldMetadata Field {get; private set;}
+ @AuraEnabled global final String FieldPath {get; private set;}
+ @AuraEnabled global final Boolean IsDbRequired {get; private set;}
+ @AuraEnabled global final Boolean IsRequired {get; private set;}
+ @AuraEnabled global final String Label {get; private set;}
+ @AuraEnabled global final String SobjectApiName {get; private set;}
- global virtual class FieldSetMemberMetadata {
-
- @AuraEnabled global final String displayType {get; private set;}
- @AuraEnabled global final FieldMetadata field {get; private set;}
- @AuraEnabled global final String fieldPath {get; private set;}
- @AuraEnabled global final Boolean isDbRequired {get; private set;}
- @AuraEnabled global final Boolean isRequired {get; private set;}
- @AuraEnabled global final String label {get; private set;}
- @AuraEnabled global final String sobjectApiName {get; private set;}
-
- private FieldSetMemberMetadata(String sobjectApiName, Schema.FieldSetMember fieldSetMember) {
- this.sobjectApiName = sobjectApiName;
-
- this.displayType = fieldSetMember.getType().name();
- this.field = this.getFieldMetadata(fieldSetMember);
- this.fieldPath = fieldSetMember.getFieldPath();
- this.isDbRequired = fieldSetMember.getDbRequired();
- this.isRequired = fieldSetMember.getRequired();
- this.label = fieldSetMember.getLabel();
+ global Integer compareTo(Object compareTo) {
+ FieldSetMemberMetadata compareToFieldSetMember = (FieldSetMemberMetadata)compareTo;
+
+ if(this.FieldPath == compareToFieldSetMember.FieldPath) return 0;
+ else if(this.FieldPath > compareToFieldSetMember.FieldPath) return 1;
+ else return -1;
+ }
+
+ private FieldSetMemberMetadata(Schema.SobjectType sobjectType, Schema.FieldSetMember fieldSetMember) {
+ this.DisplayType = fieldSetMember.getType().name();
+ this.Field = this.getFieldMetadata(sobjectType, fieldSetMember);
+ this.FieldPath = fieldSetMember.getFieldPath();
+ this.IsDbRequired = fieldSetMember.getDbRequired();
+ this.IsRequired = fieldSetMember.getRequired();
+ this.Label = fieldSetMember.getLabel();
+ this.SobjectApiName = String.valueOf(sobjectType);
}
- private FieldMetadata getFieldMetadata(Schema.FieldSetMember fieldSetMember) {
+ private FieldMetadata getFieldMetadata(Schema.SobjectType sobjectType, Schema.FieldSetMember fieldSetMember) {
FieldMetadata fieldMetadata;
List fieldChain = fieldSetMember.getFieldPath().split('\\.');
if(fieldChain.size() == 0) return fieldMetadata;
- Schema.SObjectType currentFieldSObjectType = Schema.getGlobalDescribe().get(this.sobjectApiName);
- String currentFieldSObjectApiName = this.sobjectApiName;
+ Schema.SobjectType currentFieldSobjectType = Schema.getGlobalDescribe().get(this.sobjectApiName);
+ String currentFieldSobjectApiName = String.valueOf(sobjectType);
String currentFieldApiName;
for(Integer i = 0; i < fieldChain.size(); i++) {
currentFieldApiName = fieldChain[i];
- for(Schema.SObjectField sobjectField : Schema.getGlobalDescribe().get(currentFieldSObjectApiName).getDescribe().fields.getMap().values()) {
+ for(Schema.SobjectField sobjectField : Schema.getGlobalDescribe().get(currentFieldSobjectApiName).getDescribe().fields.getMap().values()) {
DescribeFieldResult fieldDescribe = sobjectField.getDescribe();
- if(fieldDescribe.getRelationshipName() == currentFieldApiName && !fieldDescribe.getReferenceTo().isEmpty()) {
- currentFieldSObjectType = fieldDescribe.getReferenceTo()[0];
- currentFieldSObjectApiName = currentFieldSObjectType.getDescribe().getName();
-
- break;
- }
+ if(fieldDescribe.getRelationshipName() != currentFieldApiName) continue;
+ if(fieldDescribe.getReferenceTo().isEmpty()) continue;
+ currentFieldSobjectType = fieldDescribe.getReferenceTo()[0];
+ currentFieldSobjectApiName = currentFieldSobjectType.getDescribe().getName();
+ break;
}
}
- return new FieldMetadata(currentFieldSObjectApiName, currentFieldApiName);
+ return new FieldMetadata(currentFieldSobjectApiName, currentFieldApiName);
}
}
diff --git a/src/classes/FieldSetMetadata.cls-meta.xml b/src/classes/FieldSetMetadata.cls-meta.xml
index f3bac1f..800e53c 100644
--- a/src/classes/FieldSetMetadata.cls-meta.xml
+++ b/src/classes/FieldSetMetadata.cls-meta.xml
@@ -1,5 +1,5 @@
- 41.0
+ 43.0
Active
diff --git a/src/classes/FieldSetMetadata_Tests.cls b/src/classes/FieldSetMetadata_Tests.cls
index a681f4a..d7f44b0 100644
--- a/src/classes/FieldSetMetadata_Tests.cls
+++ b/src/classes/FieldSetMetadata_Tests.cls
@@ -12,7 +12,7 @@ private class FieldSetMetadata_Tests {
Test.startTest();
- String sobjectName = String.valueOf(fieldSet.getSObjectType());
+ String sobjectName = String.valueOf(fieldSet.getSobjectType());
String fieldSetNamespace = fieldSet.getNamespace() == null ? '' : fieldSet.getNamespace() + '__';
String fieldSetName = fieldSetNamespace + fieldSet.getName();
FieldSetMetadata fieldSetMetadata = new FieldSetMetadata(sobjectName, fieldSetName);
@@ -39,11 +39,11 @@ private class FieldSetMetadata_Tests {
private static Schema.FieldSet getFieldSet() {
// Dynamically check for field sets in some of the most commonly used objects
// If not results are found, then test coverage will drop
- List commonSObjectNames = new List{
+ List commonSobjectNames = new List{
'Account', 'Lead', 'Contact', 'Opportunity'
};
- for(String sobjectName : commonSObjectNames) {
- Schema.DescribeSObjectResult sobjectDescribe = Schema.getGlobalDescribe().get(sobjectName).getDescribe();
+ for(String sobjectName : commonSobjectNames) {
+ Schema.DescribeSobjectResult sobjectDescribe = Schema.getGlobalDescribe().get(sobjectName).getDescribe();
// If there are any fields sets found, return the first one
if(sobjectDescribe.fieldSets.getMap().isEmpty() == false) return sobjectDescribe.fieldSets.getMap().values()[0];
}
@@ -55,14 +55,14 @@ private class FieldSetMetadata_Tests {
if(fieldSet.getNamespace() != null) namespacePrefix = fieldSet.getNamespace() + '__';
String fieldSetName = namespacePrefix + fieldSet.getName();
- System.assertEquals(fieldSetName, fieldSetMetadata.apiName);
- System.assertEquals(fieldSet.getDescription(), fieldSetMetadata.description);
- System.assertEquals(fieldSet.getFields().size(), fieldSetMetadata.fieldSetMembers.size());
+ System.assertEquals(fieldSetName, fieldSetMetadata.ApiName);
+ System.assertEquals(fieldSet.getDescription(), fieldSetMetadata.Description);
+ System.assertEquals(fieldSet.getFields().size(), fieldSetMetadata.FieldSetMembers.size());
// TODO add asserts for field set members' field metadata
- System.assertEquals(fieldSet.getLabel(), fieldSetMetadata.label);
+ System.assertEquals(fieldSet.getLabel(), fieldSetMetadata.Label);
// TODO add assert for localName
- System.assertEquals(fieldSet.getNamespace(), fieldSetMetadata.namespace);
- System.assertEquals(String.valueOf(fieldSet.getSObjectType()), fieldSetMetadata.sobjectApiName);
+ System.assertEquals(fieldSet.getNamespace(), fieldSetMetadata.Namespace);
+ System.assertEquals(String.valueOf(fieldSet.getSobjectType()), fieldSetMetadata.SobjectApiName);
}
private static void validateCaseSentivityForJavascript(FieldSetMetadata fieldSetMetadata) {
@@ -73,13 +73,13 @@ private class FieldSetMetadata_Tests {
// One negative to confirm that the strings in our map are case sensitive
System.assert(untypedFieldSetMetadata.containsKey('APINAME') == false);
// Now for the 'real' tests
- System.assert(untypedFieldSetMetadata.containsKey('apiName'));
- System.assert(untypedFieldSetMetadata.containsKey('description'));
- System.assert(untypedFieldSetMetadata.containsKey('fieldSetMembers'));
- System.assert(untypedFieldSetMetadata.containsKey('label'));
- System.assert(untypedFieldSetMetadata.containsKey('localApiName'));
- System.assert(untypedFieldSetMetadata.containsKey('namespace'));
- System.assert(untypedFieldSetMetadata.containsKey('sobjectApiName'));
+ System.assert(untypedFieldSetMetadata.containsKey('ApiName'));
+ System.assert(untypedFieldSetMetadata.containsKey('Description'));
+ System.assert(untypedFieldSetMetadata.containsKey('FieldSetMembers'));
+ System.assert(untypedFieldSetMetadata.containsKey('Label'));
+ System.assert(untypedFieldSetMetadata.containsKey('LocalApiName'));
+ System.assert(untypedFieldSetMetadata.containsKey('Namespace'));
+ System.assert(untypedFieldSetMetadata.containsKey('SobjectApiName'));
// TODO add asserts for FieldSetMembers
}
diff --git a/src/classes/FieldSetMetadata_Tests.cls-meta.xml b/src/classes/FieldSetMetadata_Tests.cls-meta.xml
index f3bac1f..800e53c 100644
--- a/src/classes/FieldSetMetadata_Tests.cls-meta.xml
+++ b/src/classes/FieldSetMetadata_Tests.cls-meta.xml
@@ -1,5 +1,5 @@
- 41.0
+ 43.0
Active
diff --git a/src/classes/LightningMetadataController.cls b/src/classes/LightningMetadataController.cls
index b7e2322..9f5332a 100644
--- a/src/classes/LightningMetadataController.cls
+++ b/src/classes/LightningMetadataController.cls
@@ -17,10 +17,10 @@ public with sharing class LightningMetadataController {
// TODO improve this so it handles field paths for parent objects, like 'Manager.Profile.Name'
if(additionalFieldApiNames != null) userFieldNames.addAll(additionalFieldApiNames);
- DescribeSObjectResult userDescribe = Schema.User.SObjectType.getDescribe();
+ DescribeSobjectResult userDescribe = Schema.User.SobjectType.getDescribe();
List userFieldNamesToQuery = new List();
for(String fieldApiName : userFieldNames) {
- SObjectField field = userDescribe.fields.getMap().get(fieldApiName);
+ SobjectField field = userDescribe.fields.getMap().get(fieldApiName);
if(field == null) continue;
@@ -52,7 +52,7 @@ public with sharing class LightningMetadataController {
}
@AuraEnabled
- public static FieldMetadata getFieldMetadataByName(String sobjectApiName, String fieldApiName) {
+ public static FieldMetadata getFieldMetadataByApiName(String sobjectApiName, String fieldApiName) {
System.debug(LoggingLevel.INFO, 'Executing LightningMetadataController.getFieldMetadata(\'' + sobjectApiName + '\', \'' + fieldApiName + '\')');
try {
return new FieldMetadata(sobjectApiName, fieldApiName);
@@ -62,8 +62,8 @@ public with sharing class LightningMetadataController {
}
@AuraEnabled
- public static FieldSetMetadata getFieldSetMetadataByName(String sobjectApiName, String fieldSetApiName) {
- System.debug(LoggingLevel.INFO, 'Executing LightningMetadataController.getFieldSetMetadataByName(\'' + sobjectApiName + '\', \'' + fieldSetApiName + '\')');
+ public static FieldSetMetadata getFieldSetMetadataByApiName(String sobjectApiName, String fieldSetApiName) {
+ System.debug(LoggingLevel.INFO, 'Executing LightningMetadataController.getFieldSetMetadataByApiName(\'' + sobjectApiName + '\', \'' + fieldSetApiName + '\')');
try {
return new FieldSetMetadata(sobjectApiName, fieldSetApiName);
} catch(Exception ex) {
@@ -71,16 +71,6 @@ public with sharing class LightningMetadataController {
}
}
- @AuraEnabled
- public static ListViewMetadata getListViewMetadataByName(String sobjectApiName, String listViewApiName) {
- System.debug(LoggingLevel.INFO, 'Executing LightningMetadataController.getListViewMetadata(\'' + sobjectApiName + '\', \'' + listViewApiName + '\')');
- try {
- return new ListViewMetadata(sobjectApiName, listViewApiName);
- } catch(Exception ex) {
- throw new AuraHandledException(ex.getMessage());
- }
- }
-
@AuraEnabled
public static QueueMetadata getQueueMetadataById(Id queueId) {
System.debug(LoggingLevel.INFO, 'Executing LightningMetadataController.getQueueMetadataById(\'' + queueId + '\')');
@@ -92,8 +82,8 @@ public with sharing class LightningMetadataController {
}
@AuraEnabled
- public static QueueMetadata getQueueMetadataByName(String queueApiName) {
- System.debug(LoggingLevel.INFO, 'Executing LightningMetadataController.getQueueMetadataByName(\'' + queueApiName + '\')');
+ public static QueueMetadata getQueueMetadataByApiName(String queueApiName) {
+ System.debug(LoggingLevel.INFO, 'Executing LightningMetadataController.getQueueMetadataByApiName(\'' + queueApiName + '\')');
try {
return new QueueMetadata(queueApiName);
} catch(Exception ex) {
@@ -102,10 +92,10 @@ public with sharing class LightningMetadataController {
}
@AuraEnabled
- public static RecordTypeMetadata getRecordTypeMetadataById(Id recordTypeId) {
+ public static RecordTypeMetadata getRecordTypeMetadataById(String sobjectApiName, Id recordTypeId) {
System.debug(LoggingLevel.INFO, 'Executing LightningMetadataController.getRecordTypeMetadataById(\'' + recordTypeId + '\')');
try {
- return new RecordTypeMetadata(recordTypeId);
+ return new RecordTypeMetadata(Schema.getGlobalDescribe().get(sobjectApiName), recordTypeId);
} catch(Exception ex) {
throw new AuraHandledException(ex.getMessage());
}
@@ -122,10 +112,10 @@ public with sharing class LightningMetadataController {
}
@AuraEnabled
- public static SObjectMetadata getSObjectMetadataByName(String sobjectApiName) {
- System.debug(LoggingLevel.INFO, 'Executing LightningMetadataController.getSObjectMetadata(\'' + sobjectApiName + '\')');
+ public static SobjectMetadata getSobjectMetadataByApiName(String sobjectApiName) {
+ System.debug(LoggingLevel.INFO, 'Executing LightningMetadataController.getSobjectMetadataByApiName(\'' + sobjectApiName + '\')');
try {
- return new SObjectMetadata(sobjectApiName);
+ return new SobjectMetadata(sobjectApiName);
} catch(Exception ex) {
throw new AuraHandledException(ex.getMessage());
}
diff --git a/src/classes/LightningMetadataController.cls-meta.xml b/src/classes/LightningMetadataController.cls-meta.xml
index f3bac1f..800e53c 100644
--- a/src/classes/LightningMetadataController.cls-meta.xml
+++ b/src/classes/LightningMetadataController.cls-meta.xml
@@ -1,5 +1,5 @@
- 41.0
+ 43.0
Active
diff --git a/src/classes/LightningMetadataController_Tests.cls b/src/classes/LightningMetadataController_Tests.cls
index a2a0553..92cca46 100644
--- a/src/classes/LightningMetadataController_Tests.cls
+++ b/src/classes/LightningMetadataController_Tests.cls
@@ -11,7 +11,7 @@ private class LightningMetadataController_Tests {
DescribeSObjectResult sobjectDescribe = Schema.Account.SObjectType.getDescribe();
Test.startTest();
- SObjectMetadata sobjectMetadata = LightningMetadataController.getSObjectMetadataByName(sobjectName);
+ SObjectMetadata sobjectMetadata = LightningMetadataController.getSObjectMetadataByApiName(sobjectName);
Test.stopTest();
System.assertEquals(sobjectName, sobjectMetadata.apiName);
@@ -25,7 +25,7 @@ private class LightningMetadataController_Tests {
Test.startTest();
try {
- SObjectMetadata sobjectMetadata = LightningMetadataController.getSObjectMetadataByName(sobjectName);
+ SObjectMetadata sobjectMetadata = LightningMetadataController.getSObjectMetadataByApiName(sobjectName);
System.assert(false, 'Exception expected here');
} catch(Exception ex) {
System.assert(ex instanceOf AuraHandledException);
@@ -41,7 +41,7 @@ private class LightningMetadataController_Tests {
DescribeFieldResult fieldDescribe = Schema.Account.SObjectType.fields.Type.getDescribe();
Test.startTest();
- FieldMetadata fieldMetadata = LightningMetadataController.getFieldMetadataByName(sobjectName, fieldName);
+ FieldMetadata fieldMetadata = LightningMetadataController.getFieldMetadataByApiName(sobjectName, fieldName);
Test.stopTest();
System.assertEquals(sobjectName, fieldMetadata.sobjectApiName);
@@ -56,7 +56,7 @@ private class LightningMetadataController_Tests {
Test.startTest();
try {
- FieldMetadata fieldMetadata = LightningMetadataController.getFieldMetadataByName(sobjectName, fieldName);
+ FieldMetadata fieldMetadata = LightningMetadataController.getFieldMetadataByApiName(sobjectName, fieldName);
System.assert(false, 'Exception expected here');
} catch(Exception ex) {
System.assert(ex instanceOf AuraHandledException);
diff --git a/src/classes/LightningMetadataController_Tests.cls-meta.xml b/src/classes/LightningMetadataController_Tests.cls-meta.xml
index f3bac1f..800e53c 100644
--- a/src/classes/LightningMetadataController_Tests.cls-meta.xml
+++ b/src/classes/LightningMetadataController_Tests.cls-meta.xml
@@ -1,5 +1,5 @@
- 41.0
+ 43.0
Active
diff --git a/src/classes/LimitsMetadata.cls b/src/classes/LimitsMetadata.cls
new file mode 100644
index 0000000..6e9c4bf
--- /dev/null
+++ b/src/classes/LimitsMetadata.cls
@@ -0,0 +1,53 @@
+/*************************************************************************************************
+* This file is part of the SimpleMetadata project, released under the MIT License. *
+* See LICENSE file or go to https://github.com/jongpie/SimpleMetadata for full license details. *
+*************************************************************************************************/
+global class LimitsMetadata {
+
+ @AuraEnabled global final LimitUsageMetadata AggregateQueries {get; private set;}
+ @AuraEnabled global final LimitUsageMetadata AsyncCalls {get; private set;}
+ @AuraEnabled global final LimitUsageMetadata Callouts {get; private set;}
+ @AuraEnabled global final LimitUsageMetadata CpuTime {get; private set;}
+ @AuraEnabled global final LimitUsageMetadata DmlRows {get; private set;}
+ @AuraEnabled global final LimitUsageMetadata DmlStatements {get; private set;}
+ @AuraEnabled global final LimitUsageMetadata EmailInvocations {get; private set;}
+ @AuraEnabled global final LimitUsageMetadata FutureCalls {get; private set;}
+ @AuraEnabled global final LimitUsageMetadata HeapSize {get; private set;}
+ @AuraEnabled global final LimitUsageMetadata MobilePushApexCalls {get; private set;}
+ @AuraEnabled global final LimitUsageMetadata QueueableJobs {get; private set;}
+ @AuraEnabled global final LimitUsageMetadata SoqlQueryLocatorRows {get; private set;}
+ @AuraEnabled global final LimitUsageMetadata SoqlQueryRows {get; private set;}
+ @AuraEnabled global final LimitUsageMetadata SoqlQueries {get; private set;}
+ @AuraEnabled global final LimitUsageMetadata SoslSearches {get; private set;}
+
+ global LimitsMetadata() {
+ this.AggregateQueries = new LimitUsageMetadata(Limits.getAggregateQueries(), Limits.getLimitAggregateQueries());
+ this.AsyncCalls = new LimitUsageMetadata(Limits.getAsyncCalls(), Limits.getLimitAsyncCalls());
+ this.Callouts = new LimitUsageMetadata(Limits.getCallouts(), Limits.getLimitCallouts());
+ this.CpuTime = new LimitUsageMetadata(Limits.getCPUTime(), Limits.getLimitCPUTime());
+ this.DmlRows = new LimitUsageMetadata(Limits.getDmlRows(), Limits.getLimitDmlRows());
+ this.DmlStatements = new LimitUsageMetadata(Limits.getDmlStatements(), Limits.getLimitDmlStatements());
+ this.EmailInvocations = new LimitUsageMetadata(Limits.getEmailInvocations(), Limits.getLimitEmailInvocations());
+ this.FutureCalls = new LimitUsageMetadata(Limits.getFutureCalls(), Limits.getLimitFutureCalls());
+ this.HeapSize = new LimitUsageMetadata(Limits.getHeapSize(), Limits.getLimitHeapSize());
+ this.MobilePushApexCalls = new LimitUsageMetadata(Limits.getMobilePushApexCalls(), Limits.getLimitMobilePushApexCalls());
+ this.QueueableJobs = new LimitUsageMetadata(Limits.getQueueableJobs(), Limits.getLimitQueueableJobs());
+ this.SoqlQueries = new LimitUsageMetadata(Limits.getQueries(), Limits.getLimitQueries());
+ this.SoqlQueryLocatorRows = new LimitUsageMetadata(Limits.getQueryLocatorRows(), Limits.getLimitQueryLocatorRows());
+ this.SoqlQueryRows = new LimitUsageMetadata(Limits.getQueryRows(), Limits.getLimitQueryRows());
+ this.SoslSearches = new LimitUsageMetadata(Limits.getSoslQueries(), Limits.getLimitSoslQueries());
+ }
+
+ global class LimitUsageMetadata {
+
+ @AuraEnabled global final Integer Max {get; private set;}
+ @AuraEnabled global final Integer Used {get; private set;}
+
+ global LimitUsageMetadata(Integer used, Integer max){
+ this.Max = max;
+ this.Used = used;
+ }
+
+ }
+
+}
\ No newline at end of file
diff --git a/src/classes/ListViewMetadata_Tests.cls-meta.xml b/src/classes/LimitsMetadata.cls-meta.xml
similarity index 80%
rename from src/classes/ListViewMetadata_Tests.cls-meta.xml
rename to src/classes/LimitsMetadata.cls-meta.xml
index f3bac1f..800e53c 100644
--- a/src/classes/ListViewMetadata_Tests.cls-meta.xml
+++ b/src/classes/LimitsMetadata.cls-meta.xml
@@ -1,5 +1,5 @@
- 41.0
+ 43.0
Active
diff --git a/src/classes/LimitsMetadata_Tests.cls b/src/classes/LimitsMetadata_Tests.cls
new file mode 100644
index 0000000..c09d239
--- /dev/null
+++ b/src/classes/LimitsMetadata_Tests.cls
@@ -0,0 +1,73 @@
+/*************************************************************************************************
+* This file is part of the SimpleMetadata project, released under the MIT License. *
+* See LICENSE file or go to https://github.com/jongpie/SimpleMetadata for full license details. *
+*************************************************************************************************/
+@isTest
+private class LimitsMetadata_Tests {
+
+ @isTest
+ static void it_should_return_limits_metadata() {
+ LimitsMetadata limitsMetadata = new LimitsMetadata();
+ validateAttributesAreSet(limitsMetadata);
+ validateCaseSentivityForJavascript(limitsMetadata);
+ }
+
+ private static void validateAttributesAreSet(LimitsMetadata limitsMetadata) {
+ System.assertEquals(Limits.getAggregateQueries(), limitsMetadata.AggregateQueries.Used);
+ System.assertEquals(Limits.getLimitAggregateQueries(), limitsMetadata.AggregateQueries.Max);
+ System.assertEquals(Limits.getAsyncCalls(), limitsMetadata.AsyncCalls.Used);
+ System.assertEquals(Limits.getLimitAsyncCalls(), limitsMetadata.AsyncCalls.Max);
+ System.assertEquals(Limits.getCallouts(), limitsMetadata.Callouts.Used);
+ System.assertEquals(Limits.getLimitCallouts(), limitsMetadata.Callouts.Max);
+ //System.assertEquals(Limits.getCPUTime(), limitsMetadata.CpuTime.Used);
+ System.assertEquals(Limits.getLimitCPUTime(), limitsMetadata.CpuTime.Max);
+ System.assertEquals(Limits.getDMLRows(), limitsMetadata.DmlRows.Used);
+ System.assertEquals(Limits.getLimitDMLRows(), limitsMetadata.DmlRows.Max);
+ System.assertEquals(Limits.getDMLStatements(), limitsMetadata.DmlStatements.Used);
+ System.assertEquals(Limits.getLimitDMLStatements(), limitsMetadata.DmlStatements.Max);
+ System.assertEquals(Limits.getEmailInvocations(), limitsMetadata.EmailInvocations.Used);
+ System.assertEquals(Limits.getLimitEmailInvocations(), limitsMetadata.EmailInvocations.Max);
+ System.assertEquals(Limits.getFutureCalls(), limitsMetadata.FutureCalls.Used);
+ System.assertEquals(Limits.getLimitFutureCalls(), limitsMetadata.FutureCalls.Max);
+ //System.assertEquals(Limits.getHeapSize(), limitsMetadata.HeapSize.Used);
+ System.assertEquals(Limits.getLimitHeapSize(), limitsMetadata.HeapSize.Max);
+ System.assertEquals(Limits.getMobilePushApexCalls(), limitsMetadata.MobilePushApexCalls.Used);
+ System.assertEquals(Limits.getLimitMobilePushApexCalls(), limitsMetadata.MobilePushApexCalls.Max);
+ System.assertEquals(Limits.getQueueableJobs(), limitsMetadata.QueueableJobs.Used);
+ System.assertEquals(Limits.getLimitQueueableJobs(), limitsMetadata.QueueableJobs.Max);
+ System.assertEquals(Limits.getQueries(), limitsMetadata.SoqlQueries.Used);
+ System.assertEquals(Limits.getLimitQueries(), limitsMetadata.SoqlQueries.Max);
+ System.assertEquals(Limits.getQueryLocatorRows(), limitsMetadata.SoqlQueryLocatorRows.Used);
+ System.assertEquals(Limits.getLimitQueryLocatorRows(), limitsMetadata.SoqlQueryLocatorRows.Max);
+ System.assertEquals(Limits.getQueryRows(), limitsMetadata.SoqlQueryRows.Used);
+ System.assertEquals(Limits.getLimitQueryRows(), limitsMetadata.SoqlQueryRows.Max);
+ System.assertEquals(Limits.getSOSLQueries(), limitsMetadata.SoslSearches.Used);
+ System.assertEquals(Limits.getLimitSoslQueries(), limitsMetadata.SoslSearches.Max);
+ }
+
+ private static void validateCaseSentivityForJavascript(LimitsMetadata limitsMetadata) {
+ // Validate that the attributes are named exactly as expected so that javascript can rely on them
+ String jsonLimitsMetadata = JSON.serialize(limitsMetadata);
+ Map untypedLimitsMetadata = (Map)JSON.deserializeUntyped(jsonLimitsMetadata);
+
+ // One negative to confirm that the strings in our map are case sensitive
+ System.assert(untypedLimitsMetadata.containsKey('AGGREGATEQUERIES') == false);
+ // Now for the 'real' tests
+ System.assert(untypedLimitsMetadata.containsKey('AggregateQueries'));
+ System.assert(untypedLimitsMetadata.containsKey('AsyncCalls'));
+ System.assert(untypedLimitsMetadata.containsKey('Callouts'));
+ System.assert(untypedLimitsMetadata.containsKey('CpuTime'));
+ System.assert(untypedLimitsMetadata.containsKey('DmlRows'));
+ System.assert(untypedLimitsMetadata.containsKey('DmlStatements'));
+ System.assert(untypedLimitsMetadata.containsKey('EmailInvocations'));
+ System.assert(untypedLimitsMetadata.containsKey('FutureCalls'));
+ System.assert(untypedLimitsMetadata.containsKey('HeapSize'));
+ System.assert(untypedLimitsMetadata.containsKey('MobilePushApexCalls'));
+ System.assert(untypedLimitsMetadata.containsKey('QueueableJobs'));
+ System.assert(untypedLimitsMetadata.containsKey('SoqlQueries'));
+ System.assert(untypedLimitsMetadata.containsKey('SoqlQueryLocatorRows'));
+ System.assert(untypedLimitsMetadata.containsKey('SoqlQueryRows'));
+ System.assert(untypedLimitsMetadata.containsKey('SoslSearches'));
+ }
+
+}
\ No newline at end of file
diff --git a/src/classes/SObjectMetadata.cls-meta.xml b/src/classes/LimitsMetadata_Tests.cls-meta.xml
similarity index 80%
rename from src/classes/SObjectMetadata.cls-meta.xml
rename to src/classes/LimitsMetadata_Tests.cls-meta.xml
index f3bac1f..800e53c 100644
--- a/src/classes/SObjectMetadata.cls-meta.xml
+++ b/src/classes/LimitsMetadata_Tests.cls-meta.xml
@@ -1,5 +1,5 @@
- 41.0
+ 43.0
Active
diff --git a/src/classes/ListViewMetadata.cls b/src/classes/ListViewMetadata.cls
deleted file mode 100644
index 921b40b..0000000
--- a/src/classes/ListViewMetadata.cls
+++ /dev/null
@@ -1,67 +0,0 @@
-/*************************************************************************************************
-* This file is part of the SimpleMetadata project, released under the MIT License. *
-* See LICENSE file or go to https://github.com/jongpie/SimpleMetadata for full license details. *
-*************************************************************************************************/
-global class ListViewMetadata {
-
- // Stores cached query results
- private static final Map QUERIED_LIST_VIEWS_BY_ID;
- private static final Map QUERIED_LIST_VIEWS_BY_SOBJECT_AND_DEVELOPER_NAME;
- private static final Map> QUERIED_LIST_VIEW_NAMES_BY_SOBJECT_NAME;
-
- static {
- // Query & cache queues
- QUERIED_LIST_VIEWS_BY_ID = new Map();
- QUERIED_LIST_VIEWS_BY_SOBJECT_AND_DEVELOPER_NAME = new Map();
- QUERIED_LIST_VIEW_NAMES_BY_SOBJECT_NAME = new Map>();
-
- for(ListView listView : [SELECT Id, DeveloperName, IsSOQLCompatible, Name, NamespacePrefix, SObjectType FROM ListView]) {
- String namespace = listView.NamespacePrefix == null ? '' : listView.NamespacePrefix + '__';
- QUERIED_LIST_VIEWS_BY_ID.put(listView.Id, listView);
- QUERIED_LIST_VIEWS_BY_SOBJECT_AND_DEVELOPER_NAME.put(listView.SObjectType + buildFullyQualifiedName(listView), listView);
-
- if(!QUERIED_LIST_VIEW_NAMES_BY_SOBJECT_NAME.containsKey(listView.SObjectType)) {
- QUERIED_LIST_VIEW_NAMES_BY_SOBJECT_NAME.put(listView.SObjectType, new List{});
- }
- List listViewApiNames = QUERIED_LIST_VIEW_NAMES_BY_SOBJECT_NAME.get(listView.SObjectType);
- listViewApiNames.add(namespace + listView.DeveloperName);
- QUERIED_LIST_VIEW_NAMES_BY_SOBJECT_NAME.put(listView.SObjectType, listViewApiNames);
- }
- }
-
- public static List getListViewApiNames(String sobjectApiName) {
- List results = QUERIED_LIST_VIEW_NAMES_BY_SOBJECT_NAME.get(sobjectApiName);
- if(results != null) results.sort();
- return results != null ? results : new List();
- }
-
- // Method is static so it can be used in static methods and instance methods
- private static String buildFullyQualifiedName(ListView listView) {
- return (listView.NamespacePrefix == null ? '' : listView.NamespacePrefix + '__') + listView.DeveloperName;
- }
-
- @AuraEnabled global final String apiName {get; private set;}
- @AuraEnabled global final Id id {get; private set;}
- @AuraEnabled global final Boolean isSoqlCompatible {get; private set;}
- @AuraEnabled global final String label {get; private set;}
- @AuraEnabled global final String localApiName {get; private set;}
- @AuraEnabled global final String namespace {get; private set;}
- @AuraEnabled global final String sobjectApiName {get; private set;}
-
- global ListViewMetadata(String sobjectApiName, String listViewApiName) {
- this(QUERIED_LIST_VIEWS_BY_SOBJECT_AND_DEVELOPER_NAME.get(sobjectApiName + listViewApiName).Id);
- }
-
- global ListViewMetadata(Id listViewId) {
- ListView listView = QUERIED_LIST_VIEWS_BY_ID.get(listViewId);
-
- this.apiName = buildFullyQualifiedName(listView);
- this.id = listView.Id;
- this.isSoqlCompatible = listView.IsSoqlCompatible;
- this.label = listView.Name;
- this.localApiName = listView.DeveloperName;
- this.namespace = listView.NamespacePrefix;
- this.sobjectApiName = listView.SObjectType;
- }
-
-}
\ No newline at end of file
diff --git a/src/classes/ListViewMetadata_Tests.cls b/src/classes/ListViewMetadata_Tests.cls
deleted file mode 100644
index fd7657a..0000000
--- a/src/classes/ListViewMetadata_Tests.cls
+++ /dev/null
@@ -1,64 +0,0 @@
-/*************************************************************************************************
-* This file is part of the SimpleMetadata project, released under the MIT License. *
-* See LICENSE file or go to https://github.com/jongpie/SimpleMetadata for full license details. *
-*************************************************************************************************/
-@isTest
-private class ListViewMetadata_Tests {
-
- @isTest
- static void it_should_return_metadata_for_sobject_api_name_and_list_view_api_name() {
- ListView listView = [SELECT Id, IsSoqlCompatible, Name, DeveloperName, NamespacePrefix, SObjectType FROM ListView LIMIT 1];
-
- Test.startTest();
-
- String namespace = listView.NamespacePrefix == null ? '' : listView.NamespacePrefix + '__';
- ListViewMetadata listViewMetadata = new ListViewMetadata(listView.SObjectType, namespace + listView.DeveloperName);
- validateAttributesAreSet(listView, listViewMetadata);
- validateCaseSentivityForJavascript(listViewMetadata);
-
- Test.stopTest();
- }
-
- @isTest
- static void it_should_return_metadata_for_list_view_id() {
- ListView listView = [SELECT Id, IsSoqlCompatible, Name, DeveloperName, NamespacePrefix, SObjectType FROM ListView LIMIT 1];
-
- Test.startTest();
-
- ListViewMetadata listViewMetadata = new ListViewMetadata(listView.Id);
- validateAttributesAreSet(listView, listViewMetadata);
- validateCaseSentivityForJavascript(listViewMetadata);
-
- Test.stopTest();
- }
-
- private static void validateAttributesAreSet(ListView listView, ListViewMetadata listViewMetadata) {
- String apiName = (listView.NamespacePrefix == null ? '' : listView.NamespacePrefix + '__') + listView.DeveloperName;
-
- System.assertEquals(apiName, listViewMetadata.apiName);
- System.assertEquals(listView.Id, listViewMetadata.id);
- System.assertEquals(listView.IsSoqlCompatible, listViewMetadata.isSoqlCompatible);
- System.assertEquals(listView.Name, listViewMetadata.label);
- System.assertEquals(listView.DeveloperName, listViewMetadata.localApiName);
- System.assertEquals(listView.NamespacePrefix, listViewMetadata.namespace);
- System.assertEquals(listView.SObjectType, listViewMetadata.sobjectApiName);
- }
-
- private static void validateCaseSentivityForJavascript(ListViewMetadata listviewmetadata) {
- // Validate that the attributes are named exactly as expected so that javascript can rely on them
- String jsonListViewMetadata = JSON.serialize(listviewmetadata);
- Map untypedListViewMetadata = (Map)JSON.deserializeUntyped(jsonListViewMetadata);
-
- // One negative to confirm that the strings in our map are case sensitive
- System.assert(untypedListViewMetadata.containsKey('APINAME') == false);
- // Now for the 'real' tests
- System.assert(untypedListViewMetadata.containsKey('apiName'));
- System.assert(untypedListViewMetadata.containsKey('id'));
- System.assert(untypedListViewMetadata.containsKey('isSoqlCompatible'));
- System.assert(untypedListViewMetadata.containsKey('label'));
- System.assert(untypedListViewMetadata.containsKey('localApiName'));
- System.assert(untypedListViewMetadata.containsKey('namespace'));
- System.assert(untypedListViewMetadata.containsKey('sobjectApiName'));
- }
-
-}
\ No newline at end of file
diff --git a/src/classes/LookupController.cls b/src/classes/LookupController.cls
index f744d67..a3d637e 100644
--- a/src/classes/LookupController.cls
+++ b/src/classes/LookupController.cls
@@ -5,27 +5,27 @@
public with sharing class LookupController {
@AuraEnabled
- public static List search(String parentSObjectApiName, String searchFieldApiName, String searchText, String displayFieldApiName, Integer limitCount) {
+ public static List search(String parentSobjectApiName, String searchFieldApiName, String searchText, String displayFieldApiName, Integer limitCount) {
try {
- Schema.DescribeSObjectResult parentSObjectDescribe = Schema.getGlobalDescribe().get(parentSObjectApiName).getDescribe();
- SObjectMetadata parentSObjectMetadata = new SObjectMetadata(parentSObjectApiName);
+ Schema.DescribeSobjectResult parentSobjectDescribe = Schema.getGlobalDescribe().get(parentSobjectApiName).getDescribe();
+ SobjectMetadata parentSobjectMetadata = new SobjectMetadata(parentSobjectApiName);
- String query = 'SELECT Id, ' + displayFieldApiName + ' FROM ' + parentSObjectApiName;
+ String query = 'SELECT Id, ' + displayFieldApiName + ' FROM ' + parentSobjectApiName;
if(!String.isEmpty(searchText)) {
searchText = '\'%' + String.escapeSingleQuotes(searchText.trim()) + '%\'';
query += ' WHERE ' + searchFieldApiName + ' LIKE ' + searchText;
}
- Boolean canSortByLastViewdDate = parentSObjectDescribe.fields.getMap().containsKey('LastViewedDate') && String.isEmpty(searchText);
- String sortByField = canSortByLastViewdDate ? 'LastViewedDate DESC NULLS LAST' : parentSObjectMetadata.displayFieldApiName;
+ Boolean canSortByLastViewdDate = parentSobjectDescribe.fields.getMap().containsKey('LastViewedDate') && String.isEmpty(searchText);
+ String sortByField = canSortByLastViewdDate ? 'LastViewedDate DESC NULLS LAST' : parentSobjectMetadata.DisplayFieldApiName;
query += ' ORDER BY ' + sortByField
+ ' LIMIT ' + limitCount;
System.debug('query=' + query);
List searchResults = new List();
- for(SObject record : Database.query(query)) {
+ for(Sobject record : Database.query(query)) {
MatchingRecord matchingRecord = new MatchingRecord(record);
searchResults.add(matchingRecord);
}
@@ -41,30 +41,32 @@ public with sharing class LookupController {
public static MatchingRecord getRecord(Id recordId) {
if(recordId == null) return null;
- Schema.SObjectType sobjectType = recordId.getSObjectType();
- SObjectMetadata sobjectMetadata = new SObjectMetadata(sobjectType);
- List fields = new List{'Id', sobjectMetadata.displayFieldApiName};
+ Schema.SobjectType sobjectType = recordId.getSobjectType();
+ SobjectMetadata sobjectMetadata = new SobjectMetadata(sobjectType);
+ List fields = new List{'Id', sobjectMetadata.DisplayFieldApiName};
String query = 'SELECT ' + String.join(fields, ', ')
- + ' FROM ' + sobjectMetadata.apiName
+ + ' FROM ' + sobjectMetadata.ApiName
+ ' WHERE Id = \'' + recordId + '\'';
- SObject record = Database.query(query);
+ Sobject record = Database.query(query);
return new MatchingRecord(record);
}
public class MatchingRecord {
- @AuraEnabled public SObject record {get;private set;}
- @AuraEnabled public String displayText {get;private set;}
- @AuraEnabled public String sobjectName {get;private set;}
- public MatchingRecord(SObject record) {
+ @AuraEnabled public Sobject Record {get;private set;}
+ @AuraEnabled public String DisplayText {get;private set;}
+ @AuraEnabled public String SobjectName {get;private set;}
+
+ public MatchingRecord(Sobject record) {
this.record = record;
- SObjectMetadata sobjectMetadata = new SObjectMetadata(record.getSObjectType());
- this.sobjectName = sobjectMetadata.apiName;
- this.displayText = (String)record.get(sobjectMetadata.displayFieldApiName);
+ SobjectMetadata sobjectMetadata = new SobjectMetadata(record.getSobjectType());
+ this.sobjectName = sobjectMetadata.ApiName;
+ this.displayText = (String)record.get(sobjectMetadata.DisplayFieldApiName);
}
+
}
}
\ No newline at end of file
diff --git a/src/classes/LookupController.cls-meta.xml b/src/classes/LookupController.cls-meta.xml
index f3bac1f..800e53c 100644
--- a/src/classes/LookupController.cls-meta.xml
+++ b/src/classes/LookupController.cls-meta.xml
@@ -1,5 +1,5 @@
- 41.0
+ 43.0
Active
diff --git a/src/classes/LookupController_Tests.cls-meta.xml b/src/classes/LookupController_Tests.cls-meta.xml
index f3bac1f..800e53c 100644
--- a/src/classes/LookupController_Tests.cls-meta.xml
+++ b/src/classes/LookupController_Tests.cls-meta.xml
@@ -1,5 +1,5 @@
- 41.0
+ 43.0
Active
diff --git a/src/classes/QueueMetadata.cls b/src/classes/QueueMetadata.cls
index d347626..faea339 100644
--- a/src/classes/QueueMetadata.cls
+++ b/src/classes/QueueMetadata.cls
@@ -2,7 +2,7 @@
* This file is part of the SimpleMetadata project, released under the MIT License. *
* See LICENSE file or go to https://github.com/jongpie/SimpleMetadata for full license details. *
*************************************************************************************************/
-global virtual class QueueMetadata {
+global class QueueMetadata {
// Stores cached query results
private static final Map QUERIED_QUEUES_BY_ID;
@@ -14,8 +14,8 @@ global virtual class QueueMetadata {
QUERIED_QUEUES_BY_DEVELOPER_NAME = new Map();
for(Group queue : [
- SELECT DeveloperName, DoesIncludeBosses, DoesSendEmailToMembers, Email, Id, Name, OwnerId, Owner.Name, Owner.Type, RelatedId,
- (SELECT Id, SObjectType FROM QueueSObjects),
+ SELECT DeveloperName, DoesIncludeBosses, DoesSendEmailToMembers, Email, Id, Name,
+ (SELECT SobjectType FROM QueueSobjects),
(SELECT Id, GroupId, UserOrGroupId FROM GroupMembers)
FROM Group
WHERE Type = 'Queue'
@@ -31,17 +31,14 @@ global virtual class QueueMetadata {
return queueApiNames;
}
- @AuraEnabled global final String apiName {get; private set;}
- @AuraEnabled global final Boolean doesIncludeBosses {get; private set;}
- @AuraEnabled global final Boolean doesSendEmailToMembers {get; private set;}
- @AuraEnabled global final String email {get; private set;}
- @AuraEnabled global final Id id {get; private set;}
- @AuraEnabled global final String label {get; private set;}
- @AuraEnabled global final Id ownerId {get; private set;}
- @AuraEnabled global final String ownerName {get; private set;}
- @AuraEnabled global final String ownerType {get; private set;}
- @AuraEnabled global final List supportedSObjectApiNames {get; private set;}
- @AuraEnabled global final List queueMembers {get; private set;}
+ @AuraEnabled global final String ApiName {get; private set;}
+ @AuraEnabled global final Boolean DoesIncludeBosses {get; private set;}
+ @AuraEnabled global final Boolean DoesSendEmailToMembers {get; private set;}
+ @AuraEnabled global final String Email {get; private set;}
+ @AuraEnabled global final Id Id {get; private set;}
+ @AuraEnabled global final String Label {get; private set;}
+ @AuraEnabled global final List QueueMembers {get; private set;}
+ @AuraEnabled global final List SobjectApiNames {get; private set;}
global QueueMetadata(String queueApiName) {
this(QUERIED_QUEUES_BY_DEVELOPER_NAME.get(queueApiName).Id);
@@ -50,17 +47,14 @@ global virtual class QueueMetadata {
global QueueMetadata(Id queueId) {
Group queue = QUERIED_QUEUES_BY_ID.get(queueId);
- this.apiName = queue.DeveloperName;
- this.doesIncludeBosses = queue.DoesIncludeBosses;
- this.doesSendEmailToMembers = queue.DoesSendEmailToMembers;
- this.email = queue.Email;
- this.id = queue.Id;
- this.label = queue.Name;
- this.ownerId = queue.OwnerId;
- this.ownerName = queue.Owner.Name;
- this.ownerType = queue.Owner.Type;
- this.queueMembers = this.getQueueMembers(queue);
- this.supportedSObjectApiNames = this.getSupportedSObjectApiNames(queue);
+ this.ApiName = queue.DeveloperName;
+ this.DoesIncludeBosses = queue.DoesIncludeBosses;
+ this.DoesSendEmailToMembers = queue.DoesSendEmailToMembers;
+ this.Email = queue.Email;
+ this.Id = queue.Id;
+ this.Label = queue.Name;
+ this.QueueMembers = this.getQueueMembers(queue);
+ this.SobjectApiNames = this.getSobjectApiNames(queue);
}
private List getQueueMembers(Group queue) {
@@ -68,30 +62,39 @@ global virtual class QueueMetadata {
for(GroupMember queueMember : queue.GroupMembers) {
queueMembers.add(new QueueMemberMetadata(queueMember));
}
+ queueMembers.sort();
return queueMembers;
}
- private List getSupportedSObjectApiNames(Group queue) {
- List supportedSObjectApiNames = new List();
- for(QueueSObject queueSObject : queue.QueueSObjects) {
- supportedSObjectApiNames.add(queueSObject.SObjectType);
+ private List getSobjectApiNames(Group queue) {
+ List sobjectApiNames = new List();
+ for(QueueSobject queueSobject : queue.QueueSobjects) {
+ sobjectApiNames.add(queueSobject.SobjectType);
}
- supportedSObjectApiNames.sort();
- return supportedSObjectApiNames;
+ sobjectApiNames.sort();
+ return sobjectApiNames;
}
- global class QueueMemberMetadata {
+ global class QueueMemberMetadata implements Comparable {
- @AuraEnabled global final Id id {get; private set;}
- @AuraEnabled global final Id queueId {get; private set;}
- @AuraEnabled global final String type {get; private set;}
- @AuraEnabled global final Id userOrGroupId {get; private set;}
+ @AuraEnabled global final Id Id {get; private set;}
+ @AuraEnabled global final Id QueueId {get; private set;}
+ @AuraEnabled global final String Type {get; private set;}
+ @AuraEnabled global final Id UserOrGroupId {get; private set;}
+
+ global Integer compareTo(Object compareTo) {
+ QueueMemberMetadata compareToQueueMember = (QueueMemberMetadata)compareTo;
+
+ if(this.UserOrGroupId == compareToQueueMember.UserOrGroupId) return 0;
+ else if(this.UserOrGroupId > compareToQueueMember.UserOrGroupId) return 1;
+ else return -1;
+ }
private QueueMemberMetadata(GroupMember groupMember) {
- this.id = groupMember.Id;
- this.queueId = groupMember.GroupId;
- this.type = String.valueOf(groupMember.UserOrGroupId.getSObjectType());
- this.userOrGroupId = groupMember.UserOrGroupId;
+ this.Id = groupMember.Id;
+ this.QueueId = groupMember.GroupId;
+ this.Type = String.valueOf(groupMember.UserOrGroupId.getSobjectType());
+ this.UserOrGroupId = groupMember.UserOrGroupId;
}
}
diff --git a/src/classes/QueueMetadata.cls-meta.xml b/src/classes/QueueMetadata.cls-meta.xml
index f3bac1f..800e53c 100644
--- a/src/classes/QueueMetadata.cls-meta.xml
+++ b/src/classes/QueueMetadata.cls-meta.xml
@@ -1,5 +1,5 @@
- 41.0
+ 43.0
Active
diff --git a/src/classes/QueueMetadata_Tests.cls b/src/classes/QueueMetadata_Tests.cls
index 9ce5979..056b9b7 100644
--- a/src/classes/QueueMetadata_Tests.cls
+++ b/src/classes/QueueMetadata_Tests.cls
@@ -13,9 +13,9 @@ private class QueueMetadata_Tests {
Group queue = new Group(DeveloperName = queueDeveloperName, Name = queueDeveloperName, Type = 'Queue');
insert queue;
- // Create queue SObject
- QueueSObject queueCaseSObject = new QueueSObject(QueueId = queue.Id, SObjectType = 'Case');
- insert queueCaseSObject;
+ // Create queue Sobject
+ QueueSobject queueCaseSobject = new QueueSobject(QueueId = queue.Id, SobjectType = 'Case');
+ insert queueCaseSobject;
// Create queue members
List queueMembers = new List();
@@ -66,15 +66,12 @@ private class QueueMetadata_Tests {
}
private static void validateAttributesAreSet(Group queue, QueueMetadata queueMetadata) {
- System.assertEquals(queue.DeveloperName, queueMetadata.apiName);
- System.assertEquals(queue.DoesIncludeBosses, queueMetadata.doesIncludeBosses);
- System.assertEquals(queue.DoesSendEmailToMembers, queueMetadata.doesSendEmailToMembers);
- System.assertEquals(queue.Email, queueMetadata.email);
- System.assertEquals(queue.Name, queueMetadata.label);
- System.assertEquals(queue.OwnerId, queueMetadata.ownerId);
- System.assertEquals(queue.Owner.Name, queueMetadata.ownerName);
- System.assertEquals(queue.Owner.Type, queueMetadata.ownerType);
- System.assertEquals(queue.Id, queueMetadata.id);
+ System.assertEquals(queue.DeveloperName, queueMetadata.ApiName);
+ System.assertEquals(queue.DoesIncludeBosses, queueMetadata.DoesIncludeBosses);
+ System.assertEquals(queue.DoesSendEmailToMembers, queueMetadata.DoesSendEmailToMembers);
+ System.assertEquals(queue.Email, queueMetadata.Email);
+ System.assertEquals(queue.Id, queueMetadata.Id);
+ System.assertEquals(queue.Name, queueMetadata.Label);
}
private static void validateCaseSentivityForJavascript(QueueMetadata queueMetadata) {
@@ -85,17 +82,14 @@ private class QueueMetadata_Tests {
// One negative to confirm that the strings in our map are case sensitive
System.assert(untypedQueueMetadata.containsKey('APINAME') == false);
// Now for the 'real' tests
- System.assert(untypedQueueMetadata.containsKey('apiName'));
- System.assert(untypedQueueMetadata.containsKey('doesIncludeBosses'));
- System.assert(untypedQueueMetadata.containsKey('doesSendEmailToMembers'));
- System.assert(untypedQueueMetadata.containsKey('email'));
- System.assert(untypedQueueMetadata.containsKey('id'));
- System.assert(untypedQueueMetadata.containsKey('label'));
- System.assert(untypedQueueMetadata.containsKey('ownerId'));
- System.assert(untypedQueueMetadata.containsKey('ownerName'));
- System.assert(untypedQueueMetadata.containsKey('ownerType'));
- System.assert(untypedQueueMetadata.containsKey('supportedSObjectApiNames'));
- System.assert(untypedQueueMetadata.containsKey('queueMembers'));
+ System.assert(untypedQueueMetadata.containsKey('ApiName'));
+ System.assert(untypedQueueMetadata.containsKey('DoesIncludeBosses'));
+ System.assert(untypedQueueMetadata.containsKey('DoesSendEmailToMembers'));
+ System.assert(untypedQueueMetadata.containsKey('Email'));
+ System.assert(untypedQueueMetadata.containsKey('Id'));
+ System.assert(untypedQueueMetadata.containsKey('Label'));
+ System.assert(untypedQueueMetadata.containsKey('QueueMembers'));
+ System.assert(untypedQueueMetadata.containsKey('SobjectApiNames'));
}
}
\ No newline at end of file
diff --git a/src/classes/QueueMetadata_Tests.cls-meta.xml b/src/classes/QueueMetadata_Tests.cls-meta.xml
index f3bac1f..800e53c 100644
--- a/src/classes/QueueMetadata_Tests.cls-meta.xml
+++ b/src/classes/QueueMetadata_Tests.cls-meta.xml
@@ -1,5 +1,5 @@
- 41.0
+ 43.0
Active
diff --git a/src/classes/RecordTypeMetadata.cls b/src/classes/RecordTypeMetadata.cls
index 4930ad4..4581241 100644
--- a/src/classes/RecordTypeMetadata.cls
+++ b/src/classes/RecordTypeMetadata.cls
@@ -2,90 +2,67 @@
* This file is part of the SimpleMetadata project, released under the MIT License. *
* See LICENSE file or go to https://github.com/jongpie/SimpleMetadata for full license details. *
*************************************************************************************************/
-global virtual class RecordTypeMetadata {
+ global class RecordTypeMetadata implements Comparable {
- // Stores cached query results
- private static final Map QUERIED_RECORD_TYPES_BY_ID;
- private static final Map QUERIED_RECORD_TYPES_BY_SOBJECT_AND_DEVELOPER_API_NAME;
- private static final Map> QUERIED_RECORD_TYPE_NAMES_BY_SOBJECT_API_NAME;
-
- static {
- // Query & cache Record_Types
- QUERIED_RECORD_TYPES_BY_ID = new Map();
- // Salesforce enforces the combination of sobject name + record type developer name to be unique,
- // so we can use the combination as the key in a map
- QUERIED_RECORD_TYPES_BY_SOBJECT_AND_DEVELOPER_API_NAME = new Map();
- QUERIED_RECORD_TYPE_NAMES_BY_SOBJECT_API_NAME = new Map>();
-
- for(RecordType recordType : [SELECT Id, BusinessProcessId, Description, DeveloperName, NamespacePrefix, SObjectType FROM RecordType]) {
- String namespace = recordType.NamespacePrefix == null ? '' : recordType.NamespacePrefix + '__';
- QUERIED_RECORD_TYPES_BY_ID.put(recordType.Id, recordType);
- QUERIED_RECORD_TYPES_BY_SOBJECT_AND_DEVELOPER_API_NAME.put(recordType.SObjectType + namespace + recordType.DeveloperName, recordType);
-
- if(!QUERIED_RECORD_TYPE_NAMES_BY_SOBJECT_API_NAME.containsKey(recordType.SObjectType)) {
- QUERIED_RECORD_TYPE_NAMES_BY_SOBJECT_API_NAME.put(recordType.SObjectType, new List{});
- }
- List recordTypeApiNames = QUERIED_RECORD_TYPE_NAMES_BY_SOBJECT_API_NAME.get(recordType.SObjectType);
- recordTypeApiNames.add(namespace + recordType.DeveloperName);
- QUERIED_RECORD_TYPE_NAMES_BY_SOBJECT_API_NAME.put(recordType.SObjectType, recordTypeApiNames);
- }
- }
-
- public static List getRecordTypeApiNames(String sobjectApiName) {
- List results = QUERIED_RECORD_TYPE_NAMES_BY_SOBJECT_API_NAME.get(sobjectApiName);
- if(results != null) results.sort();
- return results != null ? results : new List();
- }
-
- @AuraEnabled global final String apiName {get; private set;}
- @AuraEnabled global final Id businessProcessId {get; private set;}
- @AuraEnabled global final String description {get; private set;}
- @AuraEnabled global final Id id {get; private set;}
- @AuraEnabled global final Boolean isActive {get; private set;}
- @AuraEnabled global final Boolean isAvailable {get; private set;}
- @AuraEnabled global final Boolean isDefault {get; private set;}
- @AuraEnabled global final Boolean isMaster {get; private set;}
- @AuraEnabled global final String label {get; private set;}
- @AuraEnabled global final String localApiName {get; private set;}
- @AuraEnabled global final String namespace {get; private set;}
- @AuraEnabled global final String sobjectApiName {get; private set;}
+ @AuraEnabled global final String ApiName {get; private set;}
+ @AuraEnabled global final Id Id {get; private set;}
+ @AuraEnabled global final Boolean IsActive {get; private set;}
+ @AuraEnabled global final Boolean IsAvailable {get; private set;}
+ @AuraEnabled global final Boolean IsDefault {get; private set;}
+ @AuraEnabled global final Boolean IsMaster {get; private set;}
+ @AuraEnabled global final String Label {get; private set;}
+ @AuraEnabled global final String LocalApiName {get; private set;}
+ @AuraEnabled global final String Namespace {get; private set;}
+ @AuraEnabled global final String SobjectApiName {get; private set;}
global RecordTypeMetadata(String sobjectApiName, String recordTypeApiName) {
- this(QUERIED_RECORD_TYPES_BY_SOBJECT_AND_DEVELOPER_API_NAME.get(sobjectApiName + recordTypeApiName).Id);
+ this(
+ Schema.getGlobalDescribe().get(sobjectApiName),
+ Schema.getGlobalDescribe().get(sobjectApiName).getDescribe().getRecordTypeInfosByDeveloperName().get(recordTypeApiName)
+ );
}
- global RecordTypeMetadata(Id recordTypeId) {
+ global RecordTypeMetadata(Schema.SobjectType sobjectType, Id recordTypeId) {
this(
- Schema.getGlobalDescribe().get(QUERIED_RECORD_TYPES_BY_ID.get(recordTypeId).SObjectType),
- Schema.getGlobalDescribe().get(QUERIED_RECORD_TYPES_BY_ID.get(recordTypeId).SObjectType).getDescribe().getRecordTypeInfosById().get(recordTypeId)
+ sobjectType,
+ sobjectType.getDescribe().getRecordTypeInfosById().get(recordTypeId)
);
}
- global RecordTypeMetadata(Schema.SObjectType sobjectType, Schema.RecordTypeInfo recordTypeInfo) {
- // recordType can be null because default master record types do not exist in the RecordType object that's queried with SOQL
- RecordType recordType = QUERIED_RECORD_TYPES_BY_ID.get(recordTypeInfo.getRecordTypeId());
+ global RecordTypeMetadata(Schema.SobjectType sobjectType, Schema.RecordTypeInfo recordTypeInfo) {
+ this.ApiName = this.getApiName(recordTypeInfo);
+ this.Id = recordTypeInfo.getRecordTypeId();
+ this.IsActive = recordTypeInfo.isActive();
+ this.IsAvailable = recordTypeInfo.isAvailable();
+ this.IsDefault = recordTypeInfo.isDefaultRecordTypeMapping();
+ this.IsMaster = recordTypeInfo.isMaster();
+ this.Label = recordTypeInfo.getName();
+ this.LocalApiName = this.getLocalApiName(recordTypeInfo.getDeveloperName());
+ this.Namespace = this.getNamespace(recordTypeInfo.getDeveloperName());
+ this.SobjectApiName = String.valueOf(sobjectType);
+ }
+
+ global Integer compareTo(Object compareTo) {
+ RecordTypeMetadata compareToRecordTypeMetadata = (RecordTypeMetadata)compareTo;
+ String key = this.SobjectApiName + this.ApiName;
+ String compareToKey = compareToRecordTypeMetadata.SobjectApiName + compareToRecordTypeMetadata.ApiName;
- this.apiName = this.getApiName(recordType);
- this.businessProcessId = recordType == null ? null : recordType.BusinessProcessId;
- this.description = recordType == null ? null : recordType.Description;
- this.id = recordTypeInfo.getRecordTypeId();
- this.isActive = recordTypeInfo.isActive();
- this.isAvailable = recordTypeInfo.isAvailable();
- this.isDefault = recordTypeInfo.isDefaultRecordTypeMapping();
- this.isMaster = recordTypeInfo.isMaster();
- this.label = recordTypeInfo.getName();
- this.localApiName = recordType == null ? null : recordType.DeveloperName;
- this.namespace = recordType == null ? null : recordType.NamespacePrefix;
- this.sobjectApiName = String.valueOf(sobjectType);
+ if(key == compareToKey) return 0;
+ else if(key > compareToKey) return 1;
+ else return -1;
}
- private String getApiName(RecordType recordType) {
- if(recordType == null) return null;
+ private String getApiName(Schema.RecordTypeInfo recordTypeInfo) {
+ String namespacePrefix = String.isEmpty(this.getNamespace(recordTypeInfo.getDeveloperName())) ? '' : this.getNamespace(recordTypeInfo.getDeveloperName()) + '__';
+ return namespacePrefix + recordTypeInfo.getDeveloperName();
+ }
- String namespacePrefix = '';
- if(recordType.NamespacePrefix != null) namespacePrefix = recordType.NamespacePrefix + '__';
+ private String getLocalApiName(String apiName) {
+ return apiName.contains('__') ? apiName.substringAfter('__') : apiName;
+ }
- return namespacePrefix + recordType.DeveloperName;
+ private String getNamespace(String apiName) {
+ return apiName.contains('__') ? apiName.substringBefore('__') : null;
}
}
\ No newline at end of file
diff --git a/src/classes/RecordTypeMetadata.cls-meta.xml b/src/classes/RecordTypeMetadata.cls-meta.xml
index f3bac1f..800e53c 100644
--- a/src/classes/RecordTypeMetadata.cls-meta.xml
+++ b/src/classes/RecordTypeMetadata.cls-meta.xml
@@ -1,5 +1,5 @@
- 41.0
+ 43.0
Active
diff --git a/src/classes/RecordTypeMetadata_Tests.cls b/src/classes/RecordTypeMetadata_Tests.cls
index 1d3ef0a..96c786d 100644
--- a/src/classes/RecordTypeMetadata_Tests.cls
+++ b/src/classes/RecordTypeMetadata_Tests.cls
@@ -5,28 +5,34 @@
@isTest
private class RecordTypeMetadata_Tests {
+ private static final String ORG_NAMESPACE_PREFIX;
+
+ static {
+ ORG_NAMESPACE_PREFIX = [SELECT NamespacePrefix FROM Organization].NamespacePrefix;
+ }
+
@isTest
static void it_should_return_record_type_metadata_for_record_type_info() {
// For larger orgs with a lot of record types, we don't need to test every record type
// We'll keep a count and stop after 5 to keep tests quick
Integer count = 0;
- Schema.SObjectType accountSObjectType = Schema.Account.SObjectType;
- for(Schema.RecordTypeInfo recordTypeInfo : Schema.SObjectType.Account.getRecordTypeInfos()) {
+ Schema.SobjectType accountSobjectType = Schema.Account.SobjectType;
+ for(Schema.RecordTypeInfo recordTypeInfo : Schema.SobjectType.Account.getRecordTypeInfos()) {
if(count >= 5) break;
- RecordTypeMetadata recordTypeMetadata = new RecordTypeMetadata(accountSObjectType, recordTypeInfo);
+ RecordTypeMetadata recordTypeMetadata = new RecordTypeMetadata(accountSobjectType, recordTypeInfo);
count++;
}
}
@isTest
static void it_should_return_record_type_metadata_for_sobject_and_record_type_api_names() {
- for(RecordType recordType : [SELECT Id, BusinessProcessId, Description, DeveloperName, NamespacePrefix, SObjectType FROM RecordType LIMIT 5]) {
- Schema.RecordTypeInfo recordTypeInfo = Schema.getGlobalDescribe().get(recordType.SObjectType).getDescribe().getRecordTypeInfosById().get(recordType.Id);
- String namespace = recordType.NamespacePrefix == null ? '' : recordType.NamespacePrefix + '__';
- RecordTypeMetadata recordTypeMetadata = new RecordTypeMetadata(recordType.SObjectType, namespace + recordType.DeveloperName);
- validateAttributesAreSet(recordTypeInfo, recordType, recordType.SObjectType, recordTypeMetadata);
+ for(RecordType recordType : [SELECT Id, BusinessProcessId, Description, DeveloperName, NamespacePrefix, SobjectType FROM RecordType LIMIT 5]) {
+ Schema.RecordTypeInfo recordTypeInfo = Schema.getGlobalDescribe().get(recordType.SobjectType).getDescribe().getRecordTypeInfosById().get(recordType.Id);
+ String namespace = recordType.NamespacePrefix == null || recordType.NamespacePrefix == ORG_NAMESPACE_PREFIX ? '' : recordType.NamespacePrefix + '__';
+ RecordTypeMetadata recordTypeMetadata = new RecordTypeMetadata(recordType.SobjectType, namespace + recordType.DeveloperName);
+ validateAttributesAreSet(recordTypeInfo, recordType, recordType.SobjectType, recordTypeMetadata);
validateCaseSentivityForJavascript(recordTypeMetadata);
}
}
@@ -34,7 +40,7 @@ private class RecordTypeMetadata_Tests {
@isTest
static void it_should_return_record_type_metadata_for_record_type_id() {
Schema.RecordTypeInfo queryableRecordTypeInfo;
- for(Schema.RecordTypeInfo recordTypeInfo : Schema.SObjectType.Account.getRecordTypeInfos()) {
+ for(Schema.RecordTypeInfo recordTypeInfo : Schema.SobjectType.Account.getRecordTypeInfos()) {
if(recordTypeInfo.isMaster()) continue;
queryableRecordTypeInfo = recordTypeInfo;
@@ -43,32 +49,34 @@ private class RecordTypeMetadata_Tests {
if(queryableRecordTypeInfo == null) return; // This will be null in orgs with no record types, so the test can't finish
- RecordTypeMetadata recordTypeMetadata = new RecordTypeMetadata(queryableRecordTypeInfo.getRecordTypeId());
+ RecordTypeMetadata recordTypeMetadata = new RecordTypeMetadata(Schema.Account.SobjectType, queryableRecordTypeInfo.getRecordTypeId());
RecordType recordType = [
- SELECT Id, BusinessProcessId, Description, DeveloperName, NamespacePrefix, SObjectType
+ SELECT Id, DeveloperName, NamespacePrefix, SobjectType
FROM RecordType WHERE Id = :queryableRecordTypeInfo.getRecordTypeId()
];
- validateAttributesAreSet(queryableRecordTypeInfo, recordType, recordType.SObjectType, recordTypeMetadata);
+ validateAttributesAreSet(queryableRecordTypeInfo, recordType, recordType.SobjectType, recordTypeMetadata);
validateCaseSentivityForJavascript(recordTypeMetadata);
}
private static void validateAttributesAreSet(RecordTypeInfo recordTypeInfo, RecordType recordType, String sobjectApiName, RecordTypeMetadata recordTypeMetadata) {
+ String namespace;
String namespacePrefix = '';
- if(recordType != null && recordType.NamespacePrefix != null) namespacePrefix = recordType.NamespacePrefix + '__';
+ if(recordType != null && recordType.NamespacePrefix != null && recordType.NamespacePrefix != ORG_NAMESPACE_PREFIX) {
+ namespace = recordType.NamespacePrefix;
+ namespacePrefix = recordType.NamespacePrefix + '__';
+ }
String recordTypeName = recordType == null ? null : namespacePrefix + recordType.DeveloperName;
- System.assertEquals(recordType == null ? null : recordTypeName, recordTypeMetadata.apiName);
- System.assertEquals(recordType == null ? null : recordType.BusinessProcessId, recordTypeMetadata.businessProcessId);
- System.assertEquals(recordType == null ? null : recordType.Description, recordTypeMetadata.description);
- System.assertEquals(recordTypeInfo.getRecordTypeId(), recordTypeMetadata.id);
- System.assertEquals(recordTypeInfo.isActive(), recordTypeMetadata.isActive);
- System.assertEquals(recordTypeInfo.isAvailable(), recordTypeMetadata.isAvailable);
- System.assertEquals(recordTypeInfo.isDefaultRecordTypeMapping(), recordTypeMetadata.isDefault);
- System.assertEquals(recordTypeInfo.isMaster(), recordTypeMetadata.isMaster);
- System.assertEquals(recordTypeInfo.getName(), recordTypeMetadata.label);
- System.assertEquals(recordType == null ? null : recordType.DeveloperName, recordTypeMetadata.localApiName);
- System.assertEquals(recordType == null ? null : recordType.NamespacePrefix, recordTypeMetadata.namespace);
- System.assertEquals(sobjectApiName, recordTypeMetadata.sobjectApiName);
+ System.assertEquals(recordType == null ? null : recordTypeName, recordTypeMetadata.ApiName);
+ System.assertEquals(recordTypeInfo.getRecordTypeId(), recordTypeMetadata.Id);
+ System.assertEquals(recordTypeInfo.isActive(), recordTypeMetadata.IsActive);
+ System.assertEquals(recordTypeInfo.isAvailable(), recordTypeMetadata.IsAvailable);
+ System.assertEquals(recordTypeInfo.isDefaultRecordTypeMapping(), recordTypeMetadata.IsDefault);
+ System.assertEquals(recordTypeInfo.isMaster(), recordTypeMetadata.IsMaster);
+ System.assertEquals(recordTypeInfo.getName(), recordTypeMetadata.Label);
+ System.assertEquals(recordType == null ? null : recordType.DeveloperName, recordTypeMetadata.LocalApiName);
+ System.assertEquals(recordType == null ? null : namespace, recordTypeMetadata.Namespace);
+ System.assertEquals(sobjectApiName, recordTypeMetadata.SobjectApiName);
}
private static void validateCaseSentivityForJavascript(RecordTypeMetadata recordTypeMetadata) {
@@ -79,18 +87,16 @@ private class RecordTypeMetadata_Tests {
// One negative to confirm that the strings in our map are case sensitive
System.assert(untypedRecordTypeMetadata.containsKey('APINAME') == false);
// Now for the 'real' tests
- System.assert(untypedRecordTypeMetadata.containsKey('apiName'));
- System.assert(untypedRecordTypeMetadata.containsKey('businessProcessId'));
- System.assert(untypedRecordTypeMetadata.containsKey('description'));
- System.assert(untypedRecordTypeMetadata.containsKey('id'));
- System.assert(untypedRecordTypeMetadata.containsKey('isActive'));
- System.assert(untypedRecordTypeMetadata.containsKey('isAvailable'));
- System.assert(untypedRecordTypeMetadata.containsKey('isDefault'));
- System.assert(untypedRecordTypeMetadata.containsKey('isMaster'));
- System.assert(untypedRecordTypeMetadata.containsKey('label'));
- System.assert(untypedRecordTypeMetadata.containsKey('localApiName'));
- System.assert(untypedRecordTypeMetadata.containsKey('namespace'));
- System.assert(untypedRecordTypeMetadata.containsKey('sobjectApiName'));
+ System.assert(untypedRecordTypeMetadata.containsKey('ApiName'));
+ System.assert(untypedRecordTypeMetadata.containsKey('Id'));
+ System.assert(untypedRecordTypeMetadata.containsKey('IsActive'));
+ System.assert(untypedRecordTypeMetadata.containsKey('IsAvailable'));
+ System.assert(untypedRecordTypeMetadata.containsKey('IsDefault'));
+ System.assert(untypedRecordTypeMetadata.containsKey('IsMaster'));
+ System.assert(untypedRecordTypeMetadata.containsKey('Label'));
+ System.assert(untypedRecordTypeMetadata.containsKey('LocalApiName'));
+ System.assert(untypedRecordTypeMetadata.containsKey('Namespace'));
+ System.assert(untypedRecordTypeMetadata.containsKey('SobjectApiName'));
}
}
\ No newline at end of file
diff --git a/src/classes/RecordTypeMetadata_Tests.cls-meta.xml b/src/classes/RecordTypeMetadata_Tests.cls-meta.xml
index f3bac1f..800e53c 100644
--- a/src/classes/RecordTypeMetadata_Tests.cls-meta.xml
+++ b/src/classes/RecordTypeMetadata_Tests.cls-meta.xml
@@ -1,5 +1,5 @@
- 41.0
+ 43.0
Active
diff --git a/src/classes/SObjectMetadata.cls b/src/classes/SObjectMetadata.cls
deleted file mode 100644
index 83990dd..0000000
--- a/src/classes/SObjectMetadata.cls
+++ /dev/null
@@ -1,147 +0,0 @@
-/*************************************************************************************************
-* This file is part of the SimpleMetadata project, released under the MIT License. *
-* See LICENSE file or go to https://github.com/jongpie/SimpleMetadata for full license details. *
-*************************************************************************************************/
-global virtual class SObjectMetadata {
-
- @AuraEnabled global final String apiName {get; private set;}
- @AuraEnabled global final String displayFieldApiName {get; private set;}
- @AuraEnabled global final Boolean hasMultiCurrency {get; private set;}
- @AuraEnabled global final Boolean hasSubtypes {get; private set;}
- @AuraEnabled global final Boolean isAccessible {get; private set;}
- @AuraEnabled global final Boolean isChatterFeedEnabled {get; private set;}
- @AuraEnabled global final Boolean isCreateable {get; private set;}
- @AuraEnabled global final Boolean isCustom {get; private set;}
- @AuraEnabled global final Boolean isCustomSetting {get; private set;}
- @AuraEnabled global final Boolean isDeletable {get; private set;}
- @AuraEnabled global final Boolean isMruEnabled {get; private set;}
- @AuraEnabled global final Boolean isMergeable {get; private set;}
- @AuraEnabled global final Boolean isQueryable {get; private set;}
- @AuraEnabled global final Boolean isSearchable {get; private set;}
- @AuraEnabled global final Boolean isUndeletable {get; private set;}
- @AuraEnabled global final Boolean isUpdateable {get; private set;}
- @AuraEnabled global final List fieldApiNames {get; private set;}
- @AuraEnabled global final List fieldSetApiNames {get; private set;}
- @AuraEnabled global final String keyPrefix {get; private set;}
- @AuraEnabled global final String label {get; private set;}
- @AuraEnabled global final String labelPlural {get; private set;}
- @AuraEnabled global final List listViewApiNames {get; private set;}
- @AuraEnabled global final String localApiName {get; private set;}
- @AuraEnabled global final String namespace {get; private set;}
- @AuraEnabled global final List recordTypeApiNames {get; private set;}
- @AuraEnabled global final String tabIcon {get; private set;}
-
- global SObjectMetadata(String sobjectApiName) {
- this(Schema.getGlobalDescribe().get(sobjectApiName));
- }
-
- global SObjectMetadata(Schema.SObjectType sobjectType) {
- DescribeSObjectResult sobjectDescribe = sobjectType.getDescribe();
-
- this.apiName = String.valueOf(sobjectType);
- this.displayFieldApiName = this.getDisplayFieldApiName(sobjectDescribe);
- this.fieldApiNames = this.getFieldApiNames(sobjectDescribe);
- this.fieldSetApiNames = this.getFieldSetApiNames(sobjectDescribe);
- this.hasMultiCurrency = sobjectDescribe.fields.getMap().containsKey('CurrencyIsoCode');
- this.hasSubtypes = sobjectDescribe.getHasSubtypes();
- this.isAccessible = sobjectDescribe.isAccessible();
- this.isChatterFeedEnabled = sobjectDescribe.isFeedEnabled();
- this.isCreateable = sobjectDescribe.isCreateable();
- this.isCustom = sobjectDescribe.isCustom();
- this.isCustomSetting = sobjectDescribe.isCustomSetting();
- this.isDeletable = sobjectDescribe.isDeletable();
- this.isMergeable = sobjectDescribe.isMergeable();
- this.isMruEnabled = sobjectDescribe.isMruEnabled();
- this.isQueryable = sobjectDescribe.isQueryable();
- this.isSearchable = sobjectDescribe.isSearchable();
- this.isUndeletable = sobjectDescribe.isUndeletable();
- this.isUpdateable = sobjectDescribe.isUpdateable();
- this.keyPrefix = sobjectDescribe.getKeyPrefix();
- this.label = sobjectDescribe.getLabel();
- this.labelPlural = sobjectDescribe.getLabelPlural();
- this.listViewApiNames = ListViewMetadata.getListViewApiNames(String.valueOf(sobjectType));
- this.localApiName = sobjectDescribe.getLocalName();
- this.namespace = this.getNamespace();
- this.recordTypeApiNames = RecordTypeMetadata.getRecordTypeApiNames(String.valueOf(sobjectType));
- this.tabIcon = this.getTabIcon();
- }
-
- private String getDisplayFieldApiName(Schema.DescribeSObjectResult sobjectDescribe) {
- // There are several commonly used names for the display field name - typically, Name
- // Check the common names first before resorting to looping through all SObject fields
- // The order of the field names has been sorted based on number of objects in a dev org with that field
- List educatedGuesses = new List{
- 'Name', 'DeveloperName', 'ApiName', 'Title', 'Subject',
- 'AssetRelationshipNumber', 'CaseNumber', 'ContractNumber',
- 'Domain', 'FriendlyName', 'FunctionName', 'Label', 'LocalPart',
- 'OrderItemNumber', 'OrderNumber', 'SolutionName', 'TestSuiteName'
- };
- for(String fieldName : educatedGuesses) {
- Schema.SObjectField field = sobjectDescribe.fields.getMap().get(fieldName);
-
- if(field == null) continue;
-
- Schema.DescribeFieldResult fieldDescribe = field.getDescribe();
-
- if(fieldDescribe.isNameField()) return fieldDescribe.getName();
- }
-
- // If we still don't have the displayFieldName, then loop through all fields to find it
- for(Schema.SObjectField field : sobjectDescribe.fields.getMap().values()) {
- Schema.DescribeFieldResult fieldDescribe = field.getDescribe();
-
- if(fieldDescribe.isNameField()) return fieldDescribe.getName();
- }
-
- return null;
- }
-
- private List getFieldApiNames(Schema.DescribeSObjectResult sobjectDescribe) {
- List fieldApiNames = new List();
- for(Schema.SObjectField field : sobjectDescribe.fields.getMap().values()) {
- fieldApiNames.add(String.valueOf(field));
- }
- fieldApiNames.sort();
- return fieldApiNames;
- }
-
- private List getFieldSetApiNames(Schema.DescribeSObjectResult sobjectDescribe) {
- List fieldSetApiNames = new List();
- for(Schema.FieldSet fieldSet : sobjectDescribe.fieldSets.getMap().values()) {
- String namespace = fieldSet.getNameSpace() == null ? '' : FieldSet.getNamespace() + '__';
- fieldSetApiNames.add(namespace + fieldSet.getName());
- }
- fieldSetApiNames.sort();
- return fieldSetApiNames;
- }
-
- private String getNamespace() {
- Integer localNameIndex = this.apiName.replace('__c', '').indexOf('__');
- return localNameIndex < 0 ? null : this.apiName.substring(0, localNameIndex);
- }
-
- private String getTabIcon() {
- String tabIcon;
- for(Schema.DescribeTabSetResult tabSetResult : Schema.describeTabs()) {
- for(Schema.DescribeTabResult tabResult : tabSetResult.getTabs()) {
- if(tabResult.getSObjectName() != this.apiName) continue;
-
- String iconType = tabResult.isCustom() ? 'custom' : 'standard';
- String svgIconName;
- for(Schema.DescribeIconResult icon : tabResult.getIcons()) {
- if(icon.getContentType() != 'image/svg+xml') continue;
-
- svgIconName = icon.getUrl().substringAfterLast('/').replace('.svg', '');
- tabIcon = iconType + ':' + svgIconName;
- break;
- }
- }
- }
- // Hardcoded exceptions - Salesforce doesn't return SVGs for these objects, so hardcoding is necessary
- if(tabIcon == null && this.apiName == 'Asset') tabIcon = 'standard:maintenance_asset';
- if(tabIcon == null && this.apiName == 'AssetRelationship') tabIcon = 'standard:asset_relationship';
-
- return tabIcon;
- }
-
-}
\ No newline at end of file
diff --git a/src/classes/SObjectMetadata_Tests.cls b/src/classes/SObjectMetadata_Tests.cls
deleted file mode 100644
index 1617891..0000000
--- a/src/classes/SObjectMetadata_Tests.cls
+++ /dev/null
@@ -1,108 +0,0 @@
-/*************************************************************************************************
-* This file is part of the SimpleMetadata project, released under the MIT License. *
-* See LICENSE file or go to https://github.com/jongpie/SimpleMetadata for full license details. *
-*************************************************************************************************/
-@isTest
-private class SObjectMetadata_Tests {
-
- @isTest
- static void it_should_return_metadata_for_account_sobject_token() {
- SObjectMetadata accountMetadata = new SObjectMetadata(Schema.Account.SObjectType);
- validateAttributesAreSet(accountMetadata);
- validateCaseSentivityForJavascript(accountMetadata);
- }
-
- @isTest
- static void it_should_return_metadata_for_account_sobject_api_name() {
- SObjectMetadata accountMetadata = new SObjectMetadata('Account');
- validateAttributesAreSet(accountMetadata);
- validateCaseSentivityForJavascript(accountMetadata);
- }
-
- private static void validateAttributesAreSet(SObjectMetadata sobjectMetadata) {
- Schema.DescribeSObjectResult accountDescribe = Schema.Account.SObjectType.getDescribe();
-
- System.assertEquals('Account', sobjectMetadata.apiName);
- System.assertEquals('Name', sobjectMetadata.displayFieldApiName);
- System.assertEquals(accountDescribe.fields.getMap().size(), sobjectMetadata.fieldApiNames.size());
- System.assertEquals(accountDescribe.getHasSubtypes(), sobjectMetadata.hasSubtypes);
- System.assertEquals(accountDescribe.isAccessible(), sobjectMetadata.isAccessible);
- System.assertEquals(accountDescribe.isFeedEnabled(), sobjectMetadata.isChatterFeedEnabled);
- System.assertEquals(accountDescribe.isCreateable(), sobjectMetadata.isCreateable);
- System.assertEquals(accountDescribe.isCustom(), sobjectMetadata.isCustom);
- System.assertEquals(accountDescribe.isCustomSetting(), sobjectMetadata.isCustomSetting);
- System.assertEquals(accountDescribe.isDeletable(), sobjectMetadata.isDeletable);
- System.assertEquals(accountDescribe.isMergeable(), sobjectMetadata.isMergeable);
- System.assertEquals(accountDescribe.isMruEnabled(), sobjectMetadata.isMRUEnabled);
- System.assertEquals(accountDescribe.isQueryable(), sobjectMetadata.isQueryable);
- System.assertEquals(accountDescribe.isSearchable(), sobjectMetadata.isSearchable);
- System.assertEquals(accountDescribe.isUndeletable(), sobjectMetadata.isUndeletable);
- System.assertEquals(accountDescribe.isUpdateable(), sobjectMetadata.isUpdateable);
- System.assertEquals(accountDescribe.getKeyPrefix(), sobjectMetadata.keyPrefix);
- System.assertEquals(accountDescribe.getLabel(), sobjectMetadata.label);
- System.assertEquals(accountDescribe.getLabelPlural(), sobjectMetadata.labelPlural);
- System.assertEquals(accountDescribe.getLocalName(), sobjectMetadata.localApiName);
- System.assertEquals('standard:account', sobjectMetadata.tabIcon);
-
- System.assertNotEquals(null, sobjectMetadata.apiName);
- System.assertNotEquals(null, sobjectMetadata.displayFieldApiName);
- System.assertNotEquals(null, sobjectMetadata.hasMultiCurrency);
- System.assertNotEquals(null, sobjectMetadata.hasSubtypes);
- System.assertNotEquals(null, sobjectMetadata.isAccessible);
- System.assertNotEquals(null, sobjectMetadata.isChatterFeedEnabled);
- System.assertNotEquals(null, sobjectMetadata.isCreateable);
- System.assertNotEquals(null, sobjectMetadata.isCustom);
- System.assertNotEquals(null, sobjectMetadata.isCustomSetting);
- System.assertNotEquals(null, sobjectMetadata.isDeletable);
- System.assertNotEquals(null, sobjectMetadata.isMruEnabled);
- System.assertNotEquals(null, sobjectMetadata.isMergeable);
- System.assertNotEquals(null, sobjectMetadata.isQueryable);
- System.assertNotEquals(null, sobjectMetadata.isSearchable);
- System.assertNotEquals(null, sobjectMetadata.isUndeletable);
- System.assertNotEquals(null, sobjectMetadata.isUpdateable);
- System.assertNotEquals(null, sobjectMetadata.fieldApiNames);
- System.assertNotEquals(null, sobjectMetadata.fieldSetApiNames);
- System.assertNotEquals(null, sobjectMetadata.keyPrefix);
- System.assertNotEquals(null, sobjectMetadata.label);
- System.assertNotEquals(null, sobjectMetadata.labelPlural);
- System.assertNotEquals(null, sobjectMetadata.localApiName);
- System.assertNotEquals(null, sobjectMetadata.tabIcon);
- }
-
- private static void validateCaseSentivityForJavascript(SObjectMetadata sobjectMetadata) {
- // Validate that the attributes are named exactly as expected so that javascript can rely on them
- String jsonSObjectMetadata = JSON.serialize(sobjectMetadata);
- Map untypedSObjectMetadata = (Map)JSON.deserializeUntyped(jsonSObjectMetadata);
-
- // One negative to confirm that the strings in our map are case sensitive
- System.assert(untypedSObjectMetadata.containsKey('APINAME') == false);
- // Now for the 'real' tests
- System.assert(untypedSObjectMetadata.containsKey('apiName'));
- System.assert(untypedSObjectMetadata.containsKey('displayFieldApiName'));
- System.assert(untypedSObjectMetadata.containsKey('hasMultiCurrency'));
- System.assert(untypedSObjectMetadata.containsKey('hasSubtypes'));
- System.assert(untypedSObjectMetadata.containsKey('isAccessible'));
- System.assert(untypedSObjectMetadata.containsKey('isChatterFeedEnabled'));
- System.assert(untypedSObjectMetadata.containsKey('isCreateable'));
- System.assert(untypedSObjectMetadata.containsKey('isCustom'));
- System.assert(untypedSObjectMetadata.containsKey('isCustomSetting'));
- System.assert(untypedSObjectMetadata.containsKey('isDeletable'));
- System.assert(untypedSObjectMetadata.containsKey('isMruEnabled'));
- System.assert(untypedSObjectMetadata.containsKey('isMergeable'));
- System.assert(untypedSObjectMetadata.containsKey('isQueryable'));
- System.assert(untypedSObjectMetadata.containsKey('isSearchable'));
- System.assert(untypedSObjectMetadata.containsKey('isUndeletable'));
- System.assert(untypedSObjectMetadata.containsKey('isUpdateable'));
- System.assert(untypedSObjectMetadata.containsKey('fieldApiNames'));
- System.assert(untypedSObjectMetadata.containsKey('fieldSetApiNames'));
- System.assert(untypedSObjectMetadata.containsKey('keyPrefix'));
- System.assert(untypedSObjectMetadata.containsKey('label'));
- System.assert(untypedSObjectMetadata.containsKey('labelPlural'));
- System.assert(untypedSObjectMetadata.containsKey('listViewApiNames'));
- System.assert(untypedSObjectMetadata.containsKey('localApiName'));
- System.assert(untypedSObjectMetadata.containsKey('namespace'));
- System.assert(untypedSObjectMetadata.containsKey('recordTypeApiNames'));
- System.assert(untypedSObjectMetadata.containsKey('tabIcon'));
- }
-
-}
\ No newline at end of file
diff --git a/src/classes/SobjectMetadata.cls b/src/classes/SobjectMetadata.cls
new file mode 100644
index 0000000..ec9a781
--- /dev/null
+++ b/src/classes/SobjectMetadata.cls
@@ -0,0 +1,191 @@
+/*************************************************************************************************
+* This file is part of the SimpleMetadata project, released under the MIT License. *
+* See LICENSE file or go to https://github.com/jongpie/SimpleMetadata for full license details. *
+*************************************************************************************************/
+global class SobjectMetadata {
+
+ @AuraEnabled global final String ApiName {get; private set;}
+ @AuraEnabled global final List ChildRelationships {get; private set;}
+ @AuraEnabled global final String DisplayFieldApiName {get; private set;}
+ @AuraEnabled global final List FieldApiNames {get; private set;}
+ @AuraEnabled global final List FieldSetApiNames {get; private set;}
+ @AuraEnabled global final Boolean HasMultiCurrency {get; private set;}
+ @AuraEnabled global final Boolean HasSubtypes {get; private set;}
+ @AuraEnabled global final Boolean IsAccessible {get; private set;}
+ @AuraEnabled global final Boolean IsChatterFeedEnabled {get; private set;}
+ @AuraEnabled global final Boolean IsCreateable {get; private set;}
+ @AuraEnabled global final Boolean IsCustom {get; private set;}
+ @AuraEnabled global final Boolean IsCustomSetting {get; private set;}
+ @AuraEnabled global final Boolean IsDeletable {get; private set;}
+ @AuraEnabled global final Boolean IsMruEnabled {get; private set;}
+ @AuraEnabled global final Boolean IsMergeable {get; private set;}
+ @AuraEnabled global final Boolean IsQueryable {get; private set;}
+ @AuraEnabled global final Boolean IsSearchable {get; private set;}
+ @AuraEnabled global final Boolean IsUndeletable {get; private set;}
+ @AuraEnabled global final Boolean IsUpdateable {get; private set;}
+ @AuraEnabled global final String KeyPrefix {get; private set;}
+ @AuraEnabled global final String Label {get; private set;}
+ @AuraEnabled global final String LabelPlural {get; private set;}
+ @AuraEnabled global final String LocalApiName {get; private set;}
+ @AuraEnabled global final String Namespace {get; private set;}
+ @AuraEnabled global final List RecordTypes {get; private set;}
+ @AuraEnabled global final String TabIcon {get; private set;}
+
+ global SobjectMetadata(String sobjectApiName) {
+ this(Schema.getGlobalDescribe().get(sobjectApiName));
+ }
+
+ global SobjectMetadata(Schema.SobjectType sobjectType) {
+ DescribeSobjectResult sobjectDescribe = sobjectType.getDescribe();
+
+ this.ApiName = String.valueOf(sobjectType);
+ this.ChildRelationships = this.getChildRelationships(sobjectDescribe.getChildRelationships());
+ this.DisplayFieldApiName = this.getDisplayFieldApiName(sobjectDescribe);
+ this.FieldApiNames = this.getFieldApiNames(sobjectDescribe);
+ this.FieldSetApiNames = this.getFieldSetApiNames(sobjectDescribe);
+ this.HasMultiCurrency = sobjectDescribe.fields.getMap().containsKey('CurrencyIsoCode');
+ this.HasSubtypes = sobjectDescribe.getHasSubtypes();
+ this.IsAccessible = sobjectDescribe.isAccessible();
+ this.IsChatterFeedEnabled = sobjectDescribe.isFeedEnabled();
+ this.IsCreateable = sobjectDescribe.isCreateable();
+ this.IsCustom = sobjectDescribe.isCustom();
+ this.IsCustomSetting = sobjectDescribe.isCustomSetting();
+ this.IsDeletable = sobjectDescribe.isDeletable();
+ this.IsMergeable = sobjectDescribe.isMergeable();
+ this.IsMruEnabled = sobjectDescribe.isMruEnabled();
+ this.IsQueryable = sobjectDescribe.isQueryable();
+ this.IsSearchable = sobjectDescribe.isSearchable();
+ this.IsUndeletable = sobjectDescribe.isUndeletable();
+ this.IsUpdateable = sobjectDescribe.isUpdateable();
+ this.KeyPrefix = sobjectDescribe.getKeyPrefix();
+ this.Label = sobjectDescribe.getLabel();
+ this.LabelPlural = sobjectDescribe.getLabelPlural();
+ this.LocalApiName = sobjectDescribe.getLocalName();
+ this.Namespace = this.getNamespace();
+ this.RecordTypes = this.getRecordTypes(sobjectType, sobjectDescribe.getRecordTypeInfos());
+ this.TabIcon = this.getTabIcon();
+ }
+
+ private List getChildRelationships(List relationships) {
+ List childRelationships = new List();
+ for(Schema.ChildRelationship relationship : relationships) {
+ childRelationships.add(new ChildRelationshipMetadata(relationship));
+ }
+ childRelationships.sort();
+ return childRelationships;
+ }
+
+ private String getDisplayFieldApiName(Schema.DescribeSobjectResult sobjectDescribe) {
+ // There are several commonly used names for the display field name - typically, Name
+ // Check the common names first before resorting to looping through all Sobject fields
+ // The order of the field names has been sorted based on number of objects in a dev org with that field
+ List educatedGuesses = new List{
+ 'Name', 'DeveloperName', 'ApiName', 'Title', 'Subject',
+ 'AssetRelationshipNumber', 'CaseNumber', 'ContractNumber',
+ 'Domain', 'FriendlyName', 'FunctionName', 'Label', 'LocalPart',
+ 'OrderItemNumber', 'OrderNumber', 'SolutionName', 'TestSuiteName'
+ };
+ for(String fieldName : educatedGuesses) {
+ Schema.SobjectField field = sobjectDescribe.fields.getMap().get(fieldName);
+
+ if(field == null) continue;
+
+ Schema.DescribeFieldResult fieldDescribe = field.getDescribe();
+
+ if(fieldDescribe.isNameField()) return fieldDescribe.getName();
+ }
+
+ return null;
+ }
+
+ private List getFieldApiNames(Schema.DescribeSobjectResult sobjectDescribe) {
+ List fieldApiNames = new List();
+ for(Schema.SobjectField field : sobjectDescribe.fields.getMap().values()) {
+ fieldApiNames.add(String.valueOf(field));
+ }
+ fieldApiNames.sort();
+ return fieldApiNames;
+ }
+
+ private List getFieldSetApiNames(Schema.DescribeSobjectResult sobjectDescribe) {
+ List fieldSetApiNames = new List();
+ for(Schema.FieldSet fieldSet : sobjectDescribe.fieldSets.getMap().values()) {
+ String namespace = fieldSet.getNameSpace() == null ? '' : FieldSet.getNamespace() + '__';
+ fieldSetApiNames.add(namespace + fieldSet.getName());
+ }
+ fieldSetApiNames.sort();
+ return fieldSetApiNames;
+ }
+
+ private String getNamespace() {
+ Integer localNameIndex = this.ApiName.replace('__c', '').indexOf('__');
+ return localNameIndex < 0 ? null : this.ApiName.substring(0, localNameIndex);
+ }
+
+ private List getRecordTypes(Schema.SobjectType sobjectType, List recordTypeInfos) {
+ List recordTypes = new List();
+ for(Schema.RecordTypeInfo recordTypeInfo : recordTypeInfos) {
+ recordTypes.add(new RecordTypeMetadata(sobjectType, recordTypeInfo));
+ }
+ recordTypes.sort();
+ return recordTypes;
+ }
+
+ private String getTabIcon() {
+ String tabIcon;
+ for(Schema.DescribeTabSetResult tabSetResult : Schema.describeTabs()) {
+ if(tabIcon != null) break;
+
+ for(Schema.DescribeTabResult tabResult : tabSetResult.getTabs()) {
+ if(tabIcon != null) break;
+ if(tabResult.getSobjectName() != this.ApiName) continue;
+
+ String iconType = tabResult.isCustom() ? 'custom' : 'standard';
+ String svgIconName;
+ for(Schema.DescribeIconResult icon : tabResult.getIcons()) {
+ if(icon.getContentType() != 'image/svg+xml') continue;
+
+ svgIconName = icon.getUrl().substringAfterLast('/').replace('.svg', '');
+ tabIcon = iconType + ':' + svgIconName;
+ break;
+ }
+ }
+ }
+ // Hardcoded exceptions - Salesforce doesn't return SVGs for these objects, so hardcoding is necessary
+ if(tabIcon == null && this.ApiName == 'Asset') tabIcon = 'standard:maintenance_asset';
+ if(tabIcon == null && this.ApiName == 'AssetRelationship') tabIcon = 'standard:asset_relationship';
+
+ return tabIcon;
+ }
+
+ global class ChildRelationshipMetadata implements Comparable {
+
+ @AuraEnabled global String ChildSobjectApiName {get; private set;}
+ @AuraEnabled global String FieldApiName {get; private set;}
+ @AuraEnabled global String FieldRelationshipApiName {get; private set;}
+ @AuraEnabled global Boolean IsCascadeDelete {get; private set;}
+ @AuraEnabled global Boolean IsRestrictedDelete {get; private set;}
+ @AuraEnabled global String RelationshipApiName {get; private set;}
+
+ global ChildRelationshipMetadata(Schema.ChildRelationship childRelationship) {
+ this.ChildSobjectApiName = String.valueOf(childRelationship.getChildSobject());
+ this.FieldApiName = String.valueOf(childRelationship.getField());
+ this.FieldRelationshipApiName = childRelationship.getField().getDescribe().getRelationshipName();
+ this.IsCascadeDelete = childRelationship.isCascadeDelete();
+ this.IsRestrictedDelete = childRelationship.isRestrictedDelete();
+ this.RelationshipApiName = childRelationship.getRelationshipName();
+ }
+
+ global Integer compareTo(Object compareTo) {
+ ChildRelationshipMetadata compareToChildRelationship = (ChildRelationshipMetadata)compareTo;
+ String key = this.ChildSobjectApiName + this.FieldApiName;
+ String compareToKey = compareToChildRelationship.ChildSobjectApiName + compareToChildRelationship.FieldApiName;
+
+ if(key == compareToKey) return 0;
+ else if(key > compareToKey) return 1;
+ else return -1;
+ }
+
+ }
+
+}
\ No newline at end of file
diff --git a/src/classes/SobjectMetadata.cls-meta.xml b/src/classes/SobjectMetadata.cls-meta.xml
new file mode 100644
index 0000000..800e53c
--- /dev/null
+++ b/src/classes/SobjectMetadata.cls-meta.xml
@@ -0,0 +1,5 @@
+
+
+ 43.0
+ Active
+
diff --git a/src/classes/SobjectMetadata_Tests.cls b/src/classes/SobjectMetadata_Tests.cls
new file mode 100644
index 0000000..85dd46a
--- /dev/null
+++ b/src/classes/SobjectMetadata_Tests.cls
@@ -0,0 +1,112 @@
+/*************************************************************************************************
+* This file is part of the SimpleMetadata project, released under the MIT License. *
+* See LICENSE file or go to https://github.com/jongpie/SimpleMetadata for full license details. *
+*************************************************************************************************/
+@isTest
+private class SobjectMetadata_Tests {
+
+ @isTest
+ static void it_should_return_metadata_for_account_sobject_token() {
+ SobjectMetadata accountMetadata = new SobjectMetadata(Schema.Account.SobjectType);
+ validateAttributesAreSet(accountMetadata);
+ validateCaseSentivityForJavascript(accountMetadata);
+ }
+
+ @isTest
+ static void it_should_return_metadata_for_account_sobject_api_name() {
+ SobjectMetadata accountMetadata = new SobjectMetadata('Account');
+ validateAttributesAreSet(accountMetadata);
+ validateCaseSentivityForJavascript(accountMetadata);
+ }
+
+ private static void validateAttributesAreSet(SobjectMetadata sobjectMetadata) {
+ Schema.DescribeSobjectResult accountDescribe = Schema.Account.SobjectType.getDescribe();
+
+ System.assertEquals('Account', sobjectMetadata.ApiName);
+ System.assertEquals('Name', sobjectMetadata.DisplayFieldApiName);
+ System.assertEquals(accountDescribe.getChildRelationships().size(), sobjectMetadata.ChildRelationships.size());
+ System.assertEquals(accountDescribe.fields.getMap().size(), sobjectMetadata.FieldApiNames.size());
+ System.assertEquals(accountDescribe.getHasSubtypes(), sobjectMetadata.HasSubtypes);
+ System.assertEquals(accountDescribe.isAccessible(), sobjectMetadata.IsAccessible);
+ System.assertEquals(accountDescribe.isFeedEnabled(), sobjectMetadata.IsChatterFeedEnabled);
+ System.assertEquals(accountDescribe.isCreateable(), sobjectMetadata.IsCreateable);
+ System.assertEquals(accountDescribe.isCustom(), sobjectMetadata.IsCustom);
+ System.assertEquals(accountDescribe.isCustomSetting(), sobjectMetadata.IsCustomSetting);
+ System.assertEquals(accountDescribe.isDeletable(), sobjectMetadata.IsDeletable);
+ System.assertEquals(accountDescribe.isMergeable(), sobjectMetadata.IsMergeable);
+ System.assertEquals(accountDescribe.isMruEnabled(), sobjectMetadata.IsMRUEnabled);
+ System.assertEquals(accountDescribe.isQueryable(), sobjectMetadata.IsQueryable);
+ System.assertEquals(accountDescribe.isSearchable(), sobjectMetadata.IsSearchable);
+ System.assertEquals(accountDescribe.isUndeletable(), sobjectMetadata.IsUndeletable);
+ System.assertEquals(accountDescribe.isUpdateable(), sobjectMetadata.IsUpdateable);
+ System.assertEquals(accountDescribe.getKeyPrefix(), sobjectMetadata.KeyPrefix);
+ System.assertEquals(accountDescribe.getLabel(), sobjectMetadata.Label);
+ System.assertEquals(accountDescribe.getLabelPlural(), sobjectMetadata.LabelPlural);
+ System.assertEquals(accountDescribe.getLocalName(), sobjectMetadata.LocalApiName);
+ System.assertEquals(accountDescribe.getRecordTypeInfos().size(), sobjectMetadata.RecordTypes.size());
+ System.assertEquals('standard:account', sobjectMetadata.TabIcon);
+
+ System.assertNotEquals(null, sobjectMetadata.ApiName);
+ System.assertNotEquals(null, sobjectMetadata.ChildRelationships);
+ System.assertNotEquals(null, sobjectMetadata.DisplayFieldApiName);
+ System.assertNotEquals(null, sobjectMetadata.HasMultiCurrency);
+ System.assertNotEquals(null, sobjectMetadata.HasSubtypes);
+ System.assertNotEquals(null, sobjectMetadata.IsAccessible);
+ System.assertNotEquals(null, sobjectMetadata.IsChatterFeedEnabled);
+ System.assertNotEquals(null, sobjectMetadata.IsCreateable);
+ System.assertNotEquals(null, sobjectMetadata.IsCustom);
+ System.assertNotEquals(null, sobjectMetadata.IsCustomSetting);
+ System.assertNotEquals(null, sobjectMetadata.IsDeletable);
+ System.assertNotEquals(null, sobjectMetadata.IsMruEnabled);
+ System.assertNotEquals(null, sobjectMetadata.IsMergeable);
+ System.assertNotEquals(null, sobjectMetadata.IsQueryable);
+ System.assertNotEquals(null, sobjectMetadata.IsSearchable);
+ System.assertNotEquals(null, sobjectMetadata.IsUndeletable);
+ System.assertNotEquals(null, sobjectMetadata.IsUpdateable);
+ System.assertNotEquals(null, sobjectMetadata.FieldApiNames);
+ System.assertNotEquals(null, sobjectMetadata.FieldSetApiNames);
+ System.assertNotEquals(null, sobjectMetadata.KeyPrefix);
+ System.assertNotEquals(null, sobjectMetadata.Label);
+ System.assertNotEquals(null, sobjectMetadata.LabelPlural);
+ System.assertNotEquals(null, sobjectMetadata.LocalApiName);
+ System.assertNotEquals(null, sobjectMetadata.RecordTypes);
+ System.assertNotEquals(null, sobjectMetadata.TabIcon);
+ }
+
+ private static void validateCaseSentivityForJavascript(SobjectMetadata sobjectMetadata) {
+ // Validate that the attributes are named exactly as expected so that javascript can rely on them
+ String jsonSobjectMetadata = JSON.serialize(sobjectMetadata);
+ Map untypedSobjectMetadata = (Map)JSON.deserializeUntyped(jsonSobjectMetadata);
+
+ // One negative to confirm that the strings in our map are case sensitive
+ System.assert(untypedSobjectMetadata.containsKey('APINAME') == false);
+ // Now for the 'real' tests
+ System.assert(untypedSobjectMetadata.containsKey('ApiName'));
+ System.assert(untypedSobjectMetadata.containsKey('ChildRelationships'));
+ System.assert(untypedSobjectMetadata.containsKey('DisplayFieldApiName'));
+ System.assert(untypedSobjectMetadata.containsKey('FieldApiNames'));
+ System.assert(untypedSobjectMetadata.containsKey('FieldSetApiNames'));
+ System.assert(untypedSobjectMetadata.containsKey('HasMultiCurrency'));
+ System.assert(untypedSobjectMetadata.containsKey('HasSubtypes'));
+ System.assert(untypedSobjectMetadata.containsKey('IsAccessible'));
+ System.assert(untypedSobjectMetadata.containsKey('IsChatterFeedEnabled'));
+ System.assert(untypedSobjectMetadata.containsKey('IsCreateable'));
+ System.assert(untypedSobjectMetadata.containsKey('IsCustom'));
+ System.assert(untypedSobjectMetadata.containsKey('IsCustomSetting'));
+ System.assert(untypedSobjectMetadata.containsKey('IsDeletable'));
+ System.assert(untypedSobjectMetadata.containsKey('IsMruEnabled'));
+ System.assert(untypedSobjectMetadata.containsKey('IsMergeable'));
+ System.assert(untypedSobjectMetadata.containsKey('IsQueryable'));
+ System.assert(untypedSobjectMetadata.containsKey('IsSearchable'));
+ System.assert(untypedSobjectMetadata.containsKey('IsUndeletable'));
+ System.assert(untypedSobjectMetadata.containsKey('IsUpdateable'));
+ System.assert(untypedSobjectMetadata.containsKey('KeyPrefix'));
+ System.assert(untypedSobjectMetadata.containsKey('Label'));
+ System.assert(untypedSobjectMetadata.containsKey('LabelPlural'));
+ System.assert(untypedSobjectMetadata.containsKey('LocalApiName'));
+ System.assert(untypedSobjectMetadata.containsKey('Namespace'));
+ System.assert(untypedSobjectMetadata.containsKey('RecordTypes'));
+ System.assert(untypedSobjectMetadata.containsKey('TabIcon'));
+ }
+
+}
\ No newline at end of file
diff --git a/src/classes/SobjectMetadata_Tests.cls-meta.xml b/src/classes/SobjectMetadata_Tests.cls-meta.xml
new file mode 100644
index 0000000..800e53c
--- /dev/null
+++ b/src/classes/SobjectMetadata_Tests.cls-meta.xml
@@ -0,0 +1,5 @@
+
+
+ 43.0
+ Active
+
diff --git a/src/package.xml b/src/package.xml
index 3d1a76c..f6c6c35 100644
--- a/src/package.xml
+++ b/src/package.xml
@@ -8,5 +8,5 @@
*
AuraDefinitionBundle
- 42.0
+ 43.0