| 
 | 1 | +/**  | 
 | 2 | + * @description       :   | 
 | 3 | + * @author            : Josh Dayment  | 
 | 4 | + * @group             :   | 
 | 5 | + * @last modified on  : 12-20-2023  | 
 | 6 | + * @last modified by  : Josh Dayment  | 
 | 7 | +**/  | 
 | 8 | +public with sharing class DataFetcherObjectPickerController {   | 
 | 9 | +    @AuraEnabled(cacheable=true)  | 
 | 10 | +    public static List<Member> getObjects(List<String> availableObjectTypes) {  | 
 | 11 | +        List<Member> result = new List<Member>();  | 
 | 12 | +        Map<String, SObjectType> allTypes = Schema.getGlobalDescribe();  | 
 | 13 | + | 
 | 14 | +        Boolean isDisplayAll = false;  | 
 | 15 | +        try {  | 
 | 16 | +            if (availableObjectTypes[0]?.toLowerCase() == 'all') {  | 
 | 17 | +                availableObjectTypes.clear();  | 
 | 18 | +                isDisplayAll = true;  | 
 | 19 | + | 
 | 20 | +            }  | 
 | 21 | +        } catch (Exception e) {     | 
 | 22 | + | 
 | 23 | +        }  | 
 | 24 | + | 
 | 25 | +        if (availableObjectTypes == null || availableObjectTypes.size() == 0) {  | 
 | 26 | +            availableObjectTypes = new List<String>(allTypes.keySet());  | 
 | 27 | +        }  | 
 | 28 | + | 
 | 29 | +        for (String objType : availableObjectTypes) {  | 
 | 30 | +            Schema.DescribeSObjectResult describeObject = allTypes.get(objType).getDescribe();  | 
 | 31 | +            String objectType = describeObject.getName();  | 
 | 32 | +            String objectLabel = describeObject.getLabel();  | 
 | 33 | +            Boolean isCustom = describeObject.isCustom();  | 
 | 34 | +            if (isCustom || allowedStandardObjects.containsKey(objectType) || isDisplayAll) {  | 
 | 35 | +                if (objectLabel.substring(0,2) != '__') {  | 
 | 36 | +                    result.add(new Member(objectType, objectLabel));  | 
 | 37 | +                }  | 
 | 38 | +            }  | 
 | 39 | + | 
 | 40 | +        }  | 
 | 41 | +        result.sort();   | 
 | 42 | +          | 
 | 43 | +        return result;  | 
 | 44 | + | 
 | 45 | +    }  | 
 | 46 | +    @AuraEnabled(cacheable=true)  | 
 | 47 | +    public static List<Member> getPicklistValues(String objectApiName, String fieldName) {  | 
 | 48 | + | 
 | 49 | +        List<Member> options = new List<Member>();  | 
 | 50 | +        Schema.DescribeSObjectResult describeObject = Schema.getGlobalDescribe().get(objectApiName).getDescribe();  | 
 | 51 | +        Map<String, Schema.SObjectField> fieldMap = describeObject.fields.getMap();  | 
 | 52 | +        List<Schema.PicklistEntry> values = fieldMap.get(fieldName).getDescribe().getPickListValues();  | 
 | 53 | + | 
 | 54 | +        for (Schema.PicklistEntry a : values) {  | 
 | 55 | +            options.add(new Member(a.getValue(), a.getLabel(), a.isActive(), a.isDefaultValue()));  | 
 | 56 | +        }  | 
 | 57 | +          | 
 | 58 | +        options.sort();  | 
 | 59 | + | 
 | 60 | +        return options;  | 
 | 61 | +    }  | 
 | 62 | + | 
 | 63 | +    @JsonAccess(serializable='always' deserializable='always')  | 
 | 64 | +    public class Member implements Comparable {  | 
 | 65 | + | 
 | 66 | +        @AuraEnabled  | 
 | 67 | +        public String label;  | 
 | 68 | +        @AuraEnabled  | 
 | 69 | +        public String value;  | 
 | 70 | +        @AuraEnabled  | 
 | 71 | +        public Boolean isActive;  | 
 | 72 | +        @AuraEnabled  | 
 | 73 | +        public Boolean isDefaultValue;  | 
 | 74 | + | 
 | 75 | +      | 
 | 76 | +        public Member(String value, String label) {  | 
 | 77 | +            this.label = label;  | 
 | 78 | +            this.value = value;  | 
 | 79 | +        }  | 
 | 80 | + | 
 | 81 | +        public Member(String value, String label, Boolean isActive, Boolean isDefaultValue) {  | 
 | 82 | +            this.value = value;  | 
 | 83 | +            this.label = label;           | 
 | 84 | +            this.isActive = isActive;  | 
 | 85 | +            this.isDefaultValue = isDefaultValue;  | 
 | 86 | +        }  | 
 | 87 | + | 
 | 88 | +        public Integer compareTo(Object compareTo) {  | 
 | 89 | + | 
 | 90 | +            Member curMember = (Member) compareTo;  | 
 | 91 | + | 
 | 92 | +            if (label == curMember.label) {  | 
 | 93 | +                return 0;  | 
 | 94 | +            }  | 
 | 95 | +            if (label > curMember.label) {  | 
 | 96 | +                return 1;  | 
 | 97 | +            }  | 
 | 98 | +            return -1;  | 
 | 99 | + | 
 | 100 | +        }  | 
 | 101 | + | 
 | 102 | +    }  | 
 | 103 | + | 
 | 104 | +    private static Map<String, String> allowedStandardObjects = new Map<String, String>{  | 
 | 105 | +            'Account' => 'Account',  | 
 | 106 | +            'AccountPartner' => 'Account Partner',  | 
 | 107 | +            'Asset' => 'Asset',  | 
 | 108 | +            'AssetRelationship' => 'Asset Relationship',  | 
 | 109 | +            'AssignedResource' => 'Assigned Resource',  | 
 | 110 | +            'Campaign' => 'Campaign',  | 
 | 111 | +            'CampaignMember' => 'Campaign Member',  | 
 | 112 | +            'Case' => 'Case',  | 
 | 113 | +            'Contact' => 'Contact',  | 
 | 114 | +            'ContactRequest' => 'Contact Request',  | 
 | 115 | +            'ContentDocument' => 'File',  | 
 | 116 | +            'ContentVersion' => 'File',  | 
 | 117 | +            'ContentWorkspace' => 'Library',  | 
 | 118 | +            'Contract' => 'Contract',  | 
 | 119 | +            'ContractContactRole' => 'Contract Contact Role',  | 
 | 120 | +            'Image' => 'Image',  | 
 | 121 | +            'Individual' => 'Individual',  | 
 | 122 | +            'Lead' => 'Lead',  | 
 | 123 | +            'MaintenanceAsset' => 'Maintenance Asset',  | 
 | 124 | +            'MaintenancePlan' => 'Maintenance Plan',  | 
 | 125 | +            'Note' => 'Note',  | 
 | 126 | +            'OperatingHours' => 'Operating Hours',  | 
 | 127 | +            'Opportunity' => 'Opportunity',  | 
 | 128 | +            'OpportunityLineItem' => 'Opportunity Product',  | 
 | 129 | +            'OpportunityPartner' => 'Opportunity Partner',  | 
 | 130 | +            'Order' => 'Order',  | 
 | 131 | +            'OrderItem' => 'Order Product',  | 
 | 132 | +            'Partner' => 'Partner',  | 
 | 133 | +            'Pricebook2' => 'Price Book',  | 
 | 134 | +            'PricebookEntry' => 'Price Book Entry',  | 
 | 135 | +            'Product2' => 'Product',  | 
 | 136 | +            'RecordType' => 'Record Type',  | 
 | 137 | +            'ResourceAbsence' => 'Resource Absence',  | 
 | 138 | +            'ResourcePreference' => 'Resource Preference',  | 
 | 139 | +            'ReturnOrder' => 'Return Order',  | 
 | 140 | +            'ReturnOrderLineItem' => 'Return Order Line Item',  | 
 | 141 | +            'ServiceAppointment' => 'Service Appointment',  | 
 | 142 | +            'ServiceCrew' => 'Service Crew',  | 
 | 143 | +            'ServiceCrewMember' => 'Service Crew Member',  | 
 | 144 | +            'ServiceResource' => 'Service Resource',  | 
 | 145 | +            'ServiceResourceCapacity' => 'Resource Capacity',  | 
 | 146 | +            'ServiceResourceSkill' => 'Service Resource Skill',  | 
 | 147 | +            'ServiceTerritory' => 'Service Territory',  | 
 | 148 | +            'ServiceTerritoryLocation' => 'Service Territory Location',  | 
 | 149 | +            'ServiceTerritoryMember' => 'Service Territory Member',  | 
 | 150 | +            'Shift' => 'Shift',  | 
 | 151 | +            'Shipment' => 'Shipment',  | 
 | 152 | +            'SkillRequirement' => 'Skill Requirement',  | 
 | 153 | +            'TimeSheet' => 'Time Sheet',  | 
 | 154 | +            'TimeSheetEntry' => 'Time Sheet Entry',  | 
 | 155 | +            'TimeSlot' => 'Time Slot',  | 
 | 156 | +            'User' => 'User',  | 
 | 157 | +            'WorkOrder' => 'Work Order',  | 
 | 158 | +            'WorkOrderLineItem' => 'Work Order Line Item',  | 
 | 159 | +            'WorkType' => 'Work Type',  | 
 | 160 | +            'Quote' => 'Quote',  | 
 | 161 | +            'QuoteLineItem' => 'Quote Line Item',  | 
 | 162 | +            'FlowOrchestrationInstance' => 'Flow Orchestration Instance',  | 
 | 163 | +            'FlowOrchestrationStageInstance' => 'Flow Orchestration Stage Instance',  | 
 | 164 | +            'FlowOrchestrationStepInstance' => 'Flow Orchestration Step Instance'  | 
 | 165 | +    };  | 
 | 166 | +}  | 
0 commit comments