Skip to content

Commit

Permalink
FSC merge
Browse files Browse the repository at this point in the history
  • Loading branch information
bobbysfdev committed Nov 13, 2024
1 parent b2af5c0 commit c6c7a0b
Show file tree
Hide file tree
Showing 29 changed files with 3,416 additions and 0 deletions.
Binary file not shown.
116 changes: 116 additions & 0 deletions force-app/main/default/classes/ObjectFieldSelectorController.cls
Original file line number Diff line number Diff line change
@@ -0,0 +1,116 @@
public with sharing class ObjectFieldSelectorController {

public static final String STANDARD = 'standard';
public static final String SPECIFIC = 'specific';
public static final String CUSTOM = 'custom';
public static final String BOTH = 'both';
public static final String ANCILLARY = 'ancillary';
public static final String ALL = 'all';

@AuraEnabled
public static GetObjectsResult getObjects(String selectionType, List<String> availableObjects) {
if (String.isBlank(selectionType))
selectionType = BOTH;
selectionType = selectionType.toLowerCase();
GetObjectsResult result = new GetObjectsResult();
result.objects = new List<ObjectResult>();
List<Schema.DescribeSObjectResult> describeResults = new List<Schema.DescribeSObjectResult>();
if (selectionType == ALL) {
Map<String, Schema.SObjectType> objMap = Schema.getGlobalDescribe();
for (Schema.SObjectType objType : objMap.values()) {
describeResults.add(objType.getDescribe());
}
} else if (selectionType == SPECIFIC) {
describeResults = Schema.describeSObjects(availableObjects);
} else {
List<String> objectNames = new List<String>();
List<EntityDefinition> entityDefs = new List<EntityDefinition>();
if (selectionType == STANDARD || selectionType == BOTH) {
entityDefs.addAll([SELECT KeyPrefix, QualifiedApiName, DeveloperName FROM EntityDefinition WHERE (NOT QualifiedApiName LIKE '%__c') AND (NOT QualifiedApiName LIKE '%Feed') AND (NOT QualifiedApiName LIKE '%Tag') AND (NOT QualifiedApiName LIKE '%Share') AND (NOT QualifiedApiName LIKE '%ChangeEvent') AND (NOT QualifiedApiName LIKE '%History')]);
}
if (selectionType == CUSTOM || selectionType == BOTH) {
entityDefs.addAll([SELECT QualifiedApiName FROM EntityDefinition WHERE QualifiedApiName LIKE '%__c']);
}
if (selectionType == ANCILLARY) {
entityDefs.addAll([SELECT QualifiedApiName, DeveloperName FROM EntityDefinition WHERE QualifiedApiName LIKE '%Feed' OR QualifiedApiName LIKE '%Tag' OR QualifiedApiName LIKE '%Share' OR QualifiedApiName LIKE '%ChangeEvent' OR QualifiedApiName LIKE '%History']);
}
for (EntityDefinition def : entityDefs) {
// The standard list of EntityDefinitions may still return some odd types like metadata, so we filter out any object with double underscores
if (selectionType != STANDARD || !def.QualifiedApiName.contains('__')) {
objectNames.add(def.QualifiedApiName);
}
}
describeResults = Schema.describeSObjects(objectNames);
}
for (Schema.DescribeSObjectResult res : describeResults) {
result.objects.add(new ObjectResult(res.getLabel(), res.getName()));
}
return result;
}

@AuraEnabled(cacheable=true)
public static GetObjectFieldsResult getObjectFields(String objectName) {
GetObjectFieldsResult result = new GetObjectFieldsResult();
result.fields = new List<FieldResult>();
try {
Map<String, Schema.SObjectField> tokenMap = ((SObject)Type.forName('Schema', objectName).newInstance()).getSObjectType().getDescribe().fields.getMap();
for (Schema.SObjectField objField : tokenMap.values()) {
FieldResult newField = new FieldResult(objField.getDescribe());
System.debug(newField);
result.fields.add(newField);
}
} catch (Exception e) {
result.errorMessage = e.getMessage();
return result;
}
System.debug('about to return result, with '+ result.fields.size() +' fields');
return result;
}

public class GetObjectsResult {
@AuraEnabled public List<ObjectResult> objects;
}

public class ObjectResult {
@AuraEnabled public String label;
@AuraEnabled public String value;

public ObjectResult(String label, String value) {
this.label = label;
this.value = value;
}
}

public class GetObjectFieldsResult {
@AuraEnabled public String errorMessage;
@AuraEnabled public List<FieldResult> fields;
}

public class FieldResult {
@AuraEnabled public String apiName;
@AuraEnabled public String label;
@AuraEnabled public String dataType;
@AuraEnabled public boolean nameField;
@AuraEnabled public List<ReferenceToInfo> referenceToInfos;

public FieldResult(Schema.DescribeFieldResult fieldResult) {
this.apiName = fieldResult.getName();
this.label = fieldResult.getLabel();
this.dataType = fieldResult.getType().name();
this.nameField = fieldResult.isNameField();
List<ReferenceToInfo> refToInfos = new List<ReferenceToInfo>();
for (Schema.sObjectType objType : fieldResult.getReferenceTo()) {
refToInfos.add(new ReferenceToInfo(objType.getDescribe().getName()));
}
this.referenceToInfos = refToInfos;
}
}

public class ReferenceToInfo {
@AuraEnabled public String apiName;

public ReferenceToInfo(String apiName) {
this.apiName = apiName;
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
<?xml version="1.0" encoding="UTF-8"?>
<ApexClass xmlns="http://soap.sforce.com/2006/04/metadata">
<apiVersion>54.0</apiVersion>
<status>Active</status>
</ApexClass>
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
@isTest
public class ObjectFieldSelectorControllerTest {

@isTest
public static void testOFSController() {
ObjectFieldSelectorController.GetObjectsResult result1 = ObjectFieldSelectorController.getObjects('all', new List<String>());
ObjectFieldSelectorController.GetObjectsResult result2 = ObjectFieldSelectorController.getObjects('both', new List<String>());
ObjectFieldSelectorController.GetObjectsResult result3 = ObjectFieldSelectorController.getObjects('specific', new List<String>{'Account', 'Opportunity'});
System.assertEquals(result3.objects.size(), 2);
System.assert(result3.objects.size() < result2.objects.size());
System.assert(result2.objects.size() < result1.objects.size());

ObjectFieldSelectorController.GetObjectFieldsResult result4 = ObjectFieldSelectorController.getObjectFields('Account');
ObjectFieldSelectorController.GetObjectFieldsResult result5 = ObjectFieldSelectorController.getObjectFields('NotARealObject');
System.assert(String.isBlank(result4.errorMessage));
System.assert(!String.isBlank(result5.errorMessage));
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
<?xml version="1.0" encoding="UTF-8"?>
<ApexClass xmlns="http://soap.sforce.com/2006/04/metadata">
<apiVersion>54.0</apiVersion>
<status>Active</status>
</ApexClass>
56 changes: 56 additions & 0 deletions force-app/main/default/classes/SldsIconController.cls
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
public with sharing class SldsIconController {

static final String COMMA = ',';
static final String NEWLINE = '\r\n';
static final String SPACE = ' ';

public class Option {
@AuraEnabled
public String label {get; set;}
@AuraEnabled
public String value {get; set;}
@AuraEnabled
public String icon {get; set;}
}

@AuraEnabled (cacheable=true)
public static List<Option> getIconOptions() {

List<Option> options = new List<Option>();

Option emptyOption = new Option();
emptyOption.label = '--None--';
emptyOption.value = null;

options.add(emptyOption);

try {
StaticResource sr = [
SELECT Body
FROM StaticResource
WHERE Name = 'SldsIcons'
AND NamespacePrefix = ''
];

String content = sr.Body.toString();

List<String> rows = content.split(NEWLINE);
for( Integer i = 1; i < rows.size(); i++ ){
Option option = new Option();
List<String> columns = rows[i].split(COMMA);
option.label = columns[0].trim();
option.value = columns[0].trim();
option.icon = columns[0].trim();
columns.remove(0);

options.add(option);
}
} catch (Exception e) {
AuraHandledException ahe = new AuraHandledException(e.getMessage());
ahe.setMessage('Aura Handled Exception thrown.');
throw ahe;
}

return options;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
<?xml version="1.0" encoding="UTF-8"?>
<ApexClass xmlns="http://soap.sforce.com/2006/04/metadata">
<apiVersion>61.0</apiVersion>
<status>Active</status>
</ApexClass>
26 changes: 26 additions & 0 deletions force-app/main/default/classes/SldsIconControllerTests.cls
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
@isTest
private class SldsIconControllerTests {

@isTest
static void gracefullyHandleMissingStaticResource(){
try{
SldsIconController.getIconOptions();
} catch (Exception e){
String errorMsg = e.getMessage();
Assert.areEqual('Aura Handled Exception thrown.', errorMsg);
}
}

@isTest
static void successfullyRetrieveAndProcessStaticResource(){

List<SldsIconController.Option> results = SldsIconController.getIconOptions();

Assert.areEqual('--None--', results[0].label);
Assert.isNull(results[0].value);
Assert.isNull(results[0].icon);

}


}
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
<?xml version="1.0" encoding="UTF-8"?>
<ApexClass xmlns="http://soap.sforce.com/2006/04/metadata">
<apiVersion>61.0</apiVersion>
<status>Active</status>
</ApexClass>
3 changes: 3 additions & 0 deletions force-app/main/default/lwc/fsc_combobox/fsc_combobox.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
.disabledCursor, .disabledCursor ~ .slds-button {
cursor: not-allowed;
}
Loading

0 comments on commit c6c7a0b

Please sign in to comment.