A lightweight library of Apex classes for Salesforce that provide easy access to metadata information
Each class has at least 2 contstructors
- Constructor that accepts strings parameters - ideal for Lightning components/Javascript where strings are needed
- Constructor that accepts Apex metadata classes, like Schema.SObjectType and Schema.SObjectField - ideal for Apex development where you want something safer than strings
Each class returns an immutable DTO with no public methods. Each member variables follows these naming conventions:
- Variables are named using camelCase - this is less important in Apex development since Apex is case-insensitive, but important to note for Lightning development since Javascript is case-sensitive.
- Variables called 'name' refer to the API name or Developer Name, including the namespace prefix. Example: sobjectName = 'MyNameSpace__MyObject__c';
- Variables called 'localName' refer to the API name or Developer Name, excluding the namespace prefix. Example: sobjectName = 'MyObject__c';
- Variables called 'label' refer to the label displayed to the user. Example: new SObjectMetadata('MyObject__c').label; // Gets the localized/translated label for your custom object
- Variables called 'displayFieldName' refer to the name field of an SObject - typically, the field is actually called Name, but there are exceptions, like Case.CaseNumber, Task.Subject, Order.OrderNumber, etc.
-
Contains metadata information for the current environment. No parameters are needed to construct it.
new EnvironmentMetadata()See Sample JSON
{ "baseURL": "https://mydomain.my.salesforce.com", "instanceName": "EU11", "isChatterEnabled": true, "isKnowledgeEnabled": false, "isMultiCurrencyEnabled": false, "isPersonAccountEnabled": false, "isProduction": true, "isSandbox": false, "isTerritoryManagementEnabled": false, "name": "Jonathan Gillespie's Org", "organizationId": "00D0Y0000019999999", "organizationType": "Developer Edition", "sobjectTypeNames": [ "AcceptedEventRelation", "Account", "AccountCleanInfo", "AccountContactRole", "AccountFeed", "AccountHistory", "AccountPartner", "AccountShare", "ActionLinkGroupTemplate", "ActionLinkTemplate", "ActivityExtension", "ActivityHistory", "ActivityRecurrence", "ActivityRecurrenceException", "AdditionalNumber", "AggregateResult", "Announcement", "ApexClass", "ApexComponent", "ApexEmailNotification", "ApexLog", "ApexPage", "ApexPageInfo", "ApexTestQueueItem", "ApexTestResult", "ApexTestResultLimits", "ApexTestRunResult", "ApexTestSuite", "ApexTrigger", "AppMenuItem", "Asset", "AssetFeed", "AssetHistory", "AssetRelationship", "AssetRelationshipFeed", "AssetRelationshipHistory", "AssetShare", "AssetTokenEvent", "AssignmentRule", "AsyncApexJob", "AttachedContentDocument", "Attachment", "AuraDefinition", "AuraDefinitionBundle", "AuraDefinitionBundleInfo", "AuraDefinitionInfo", "AuthConfig", "AuthConfigProviders", "AuthProvider", "AuthSession", "BackgroundOperation", "BrandTemplate", "BusinessHours", "BusinessProcess", "CallCenter", "Campaign", "CampaignFeed", "CampaignHistory", "CampaignMember", "CampaignMemberStatus", "CampaignShare", "Case", "CaseComment", "CaseContactRole", "CaseFeed", "CaseHistory", "CaseShare", "CaseSolution", "CaseStatus", "CaseTeamMember", "CaseTeamRole", "CaseTeamTemplate", "CaseTeamTemplateMember", "CaseTeamTemplateRecord", "CategoryData", "CategoryNode", "CategoryNodeLocalization", "ChatterActivity", "ChatterConversation", "ChatterConversationMember", "ChatterExtension", "ChatterExtensionConfig", "ChatterExtensionLocalization", "ChatterMessage", "ClientBrowser", "CollaborationGroup", "CollaborationGroupFeed", "CollaborationGroupMember", "CollaborationGroupMemberRequest", "CollaborationGroupRecord", "CollaborationInvitation", "CombinedAttachment", "Community", "ConnectedApplication", "Contact", "ContactCleanInfo", "ContactFeed", "ContactHistory", "ContactShare", "ContentAsset", "ContentBody", "ContentDistribution", "ContentDistributionView", "ContentDocument", "ContentDocumentFeed", "ContentDocumentHistory", "ContentDocumentLink", "ContentFolder", "ContentFolderItem", "ContentFolderLink", "ContentFolderMember", "ContentVersion", "ContentVersionHistory", "ContentWorkspace", "ContentWorkspaceDoc", "ContentWorkspaceMember", "ContentWorkspacePermission", "ContractContactRole", "Contract", "ContractFeed", "ContractHistory", "ContractStatus", "CorsWhitelistEntry", "CronJobDetail", "CronTrigger", "CspTrustedSite", "CustomBrand", "CustomBrandAsset", "CustomObjectUserLicenseMetrics", "CustomPermission", "CustomPermissionDependency", "DandBCompany", "Dashboard", "DashboardComponent", "DashboardComponentFeed", "DashboardFeed", "DataAssessmentFieldMetric", "DataAssessmentMetric", "DataAssessmentValueMetric", "DatacloudAddress", "DatacloudCompany", "DatacloudContact", "DatacloudDandBCompany", "DatacloudOwnedEntity", "DatacloudPurchaseUsage", "DataStatistics", "DataType", "DeclinedEventRelation", "DirectMessage", "DirectMessageFeed", "DirectMessageMember", "Document", "DocumentAttachmentMap", "Domain", "DomainSite", "DuplicateRecordItem", "DuplicateRecordSet", "DuplicateRule", "EmailCapture", "EmailDomainKey", "EmailMessage", "EmailMessageRelation", "EmailServicesAddress", "EmailServicesFunction", "EmailStatus", "EmailTemplate", "EmbeddedServiceDetail", "EntityDefinition", "EntityParticle", "EntitySubscription", "Event", "EventBusSubscriber", "EventFeed", "EventLogFile", "EventRelation", "ExternalDataSource", "ExternalDataUserAuth", "FeedAttachment", "FeedComment", "FeedItem", "FeedLike", "FeedPollChoice", "FeedPollVote", "FeedRevision", "FeedSignal", "FeedTrackedChange", "FieldDefinition", "FieldPermissions", "FileSearchActivity", "FiscalYearSettings", "FlexQueueItem", "FlowInterview", "FlowInterviewShare", "Folder", "FolderedContentDocument", "ForecastShare", "Goal", "GoalFeed", "GoalHistory", "GoalLink", "GoalShare", "GrantedByLicense", "Group", "GroupMember", "Holiday", "Idea", "IdeaComment", "IdpEventLog", "InstalledMobileApp", "KnowledgeableUser", "Lead", "LeadCleanInfo", "LeadFeed", "LeadHistory", "LeadShare", "LeadStatus", "ListEmail", "ListEmailRecipientSource", "ListEmailShare", "ListView", "ListViewChart", "ListViewChartInstance", "LoginGeo", "LoginHistory", "LoginIp", "LookedUpFromActivity", "Macro", "MacroHistory", "MacroInstruction", "MacroShare", "MailmergeTemplate", "MatchingRule", "MatchingRuleItem", "Metric", "MetricDataLink", "MetricDataLinkHistory", "MetricFeed", "MetricHistory", "MetricShare", "Name", "NamedCredential", "Note", "NoteAndAttachment", "OauthToken", "ObjectPermissions", "OpenActivity", "Opportunity", "OpportunityCompetitor", "OpportunityContactRole", "OpportunityFeed", "OpportunityFieldHistory", "OpportunityHistory", "OpportunityLineItem", "OpportunityPartner", "OpportunityShare", "OpportunityStage", "Order", "OrderFeed", "OrderHistory", "OrderItem", "OrderItemFeed", "OrderItemHistory", "OrderShare", "Organization", "OrgLifecycleNotification", "OrgWideEmailAddress", "OutgoingEmail", "OutgoingEmailRelation", "OwnedContentDocument", "OwnerChangeOptionInfo", "PackageLicense", "Partner", "PartnerRole", "Period", "PermissionSet", "PermissionSetAssignment", "PermissionSetLicense", "PermissionSetLicenseAssign", "PicklistValueInfo", "PlatformAction", "PlatformCachePartition", "PlatformCachePartitionType", "Pricebook2", "Pricebook2History", "PricebookEntry", "ProcessDefinition", "ProcessInstance", "ProcessInstanceHistory", "ProcessInstanceNode", "ProcessInstanceStep", "ProcessInstanceWorkitem", "ProcessNode", "Product2", "Product2Feed", "Product2History", "Profile", "Publisher", "PushTopic", "QueueSobject", "QuoteTemplateRichTextData", "RecentlyViewed", "RecordType", "RecordTypeLocalization", "RelationshipDomain", "RelationshipInfo", "Report", "ReportFeed", "SamlSsoConfig", "Scontrol", "ScontrolLocalization", "SearchActivity", "SearchLayout", "SearchPromotionRule", "SecureAgent", "SecureAgentPlugin", "SecureAgentPluginProperty", "SecureAgentsCluster", "SecurityCustomBaseline", "SessionPermSetActivation", "SetupAuditTrail", "SetupEntityAccess", "Site", "SiteFeed", "SiteHistory", "Solution", "SolutionFeed", "SolutionHistory", "SolutionStatus", "Stamp", "StampAssignment", "StampLocalization", "StaticResource", "StreamingChannel", "StreamingChannelShare", "Task", "TaskFeed", "TaskPriority", "TaskStatus", "TenantSecret", "TenantUsageEntitlement", "TestSuiteMembership", "ThirdPartyAccountLink", "TodayGoal", "TodayGoalShare", "Topic", "TopicAssignment", "TopicFeed", "TopicLocalization", "TwoFactorInfo", "TwoFactorMethodsInfo", "TwoFactorTempCode", "UndecidedEventRelation", "User", "UserAppInfo", "UserAppMenuCustomization", "UserAppMenuCustomizationShare", "UserAppMenuItem", "UserEntityAccess", "UserFeed", "UserFieldAccess", "UserLicense", "UserListView", "UserListViewCriterion", "UserLogin", "UserPackageLicense", "UserPermissionAccess", "UserPreference", "UserProvAccount", "UserProvAccountStaging", "UserProvisioningConfig", "UserProvisioningLog", "UserProvisioningRequest", "UserProvisioningRequestShare", "UserProvMockTarget", "UserRecordAccess", "UserRole", "UserShare", "VerificationHistory", "VisualforceAccessMetrics", "Vote", "WaveCompatibilityCheckItem", "WebLink", "WebLinkLocalization", "WorkCoaching", "WorkCoachingFeed", "WorkCoachingHistory", "WorkCoachingShare", "WorkFeedback", "WorkFeedbackHistory", "WorkFeedbackQuestion", "WorkFeedbackQuestionHistory", "WorkFeedbackQuestionSet", "WorkFeedbackQuestionSetHistory", "WorkFeedbackQuestionSetShare", "WorkFeedbackQuestionShare", "WorkFeedbackRequest", "WorkFeedbackRequestFeed", "WorkFeedbackRequestHistory", "WorkFeedbackRequestShare", "WorkFeedbackShare", "WorkFeedbackTemplate", "WorkFeedbackTemplateShare", "WorkPerformanceCycle", "WorkPerformanceCycleFeed", "WorkPerformanceCycleHistory", "WorkPerformanceCycleShare" ] }
-
Contains metadata information for the specified SObject. There are 2 ways to create an instance of SObjectMetadata
- By passing the SObject's API name as a string in the constructor
new SObjectMetadata('Account')- By passing the SObject Type in the constructor
new SObjectMetadata(Schema.Account.SObjectType)Scenario: if the user has access to delete an SObject, then delete it
public class MyClass { public void deleteRecord(MyCustomObject__c myRecord) { // If the user does not have access to delete, then stop if(new SObjectMetadata('MyCustomObject__c').isDeletable == false) return; //Otherwise, delete the record delete myRecord.MyCustomField__c; } }
-
Contains metadata information for the specified field. There are 2 ways to create an instance of FieldMetadata
- By passing the SObject's API name and the field's API name as strings in the constructor
new FieldMetadata('Account', 'Type')- By passing the SObject Type and the SObject Field in the constructor
new FieldMetadata(Schema.Account.SObjectType, Schema.Account.Type)Scenario: if the user has access to edit a field, set the value
public class MyClass { public void setMyField(MyCustomObject__c myRecord) { // If the user does not have access to delete, then stop if(new FieldMetadata('MyCustomObject__c', 'MyCustomField__c').isUpdateable) { // Otherwise, set the field myRecord.MyCustomField__c = 'some value'; } }
-
Contains metadata information for the specified field set, as well as the field set's SObject and the field metadata for each field set member. There are 2 ways to create an instance of FieldMetadata
- By passing the SObject's API name and the field set's API name as strings in the constructor
new FieldSetMetadata('Lead', 'MyFieldSet')- By passing the FieldSet in the constructor
new FieldSetMetadata(SObjectType.Lead.FieldSets.MyFieldSet);
-
Contains metadata information for a record type by combinging RecordTypeInfo and RecordType objects together. There are 3 ways to create an instance of RecordTypeMetadata
- By passing the SObject's API name and the RecordType's API name (DeveloperName) in the constructor
new RecordTypeMetadata('Account', 'My_RecordType_Developer_Name');- By passing the RecordType's ID in the constructor
new RecordTypeMetadata(myAccountRecord.RecordTypeId);- By passing the Schema.SObjectType and the Schema.RecordTypeInfo in the constructor
Schema.SObjectType accountSObjectType = Schema.Account.SObjectType; Schema.RecordTypeInfo someAccountRecordTypeInfo; new RecordTypeMetadata(accountSObjectType, someAccountRecordTypeInfo);See Sample JSON
{ "businessProcessId": null, "description": "This is my example record type", "isActive": true, "isAvailable": true, "isDefaultRecordTypeMapping": true, "isMaster": false, "label": "My Record Type", "localName": "My_RecordType_Developer_Name" "name": "MyNamespace__My_RecordType_Developer_Name" "namespace": "MyNamespace", "recordTypeId": "0120Y000000EEEEE", "sobjectName": "Account" }
-
Contains metadata information for a queue, including the queue members and the supported SObject names. There are 2 ways to create an instance of QueueMetadata
- By passing the Queue's API name (DeveloperName) in the constructor
new QueueMetadata('My_Queue_Developer_Name');- By passing the Queue's ID in the constructor
Id myQueueId = '00G0Y0000000000'; new QueueMetadata(myQueueId);See Sample JSON
{ "doesIncludeBosses": true, "doesSendEmailToMembers": true, "email": "fake@test.com", "label": "My Queue", "name": "My_Queue", "ownerId": "0050Y0000000000000", "queueId": "00G0Y0000011111111", "queueMembers": [ { "queueId": "00G0Y0000011111111", "queueMemberId": "0110Y000000fHUyQAM", "type": "User", "userOrGroupId": "0050Y000001LrM3QAK" }, { "queueId": "00G0Y0000011111111", "queueMemberId": "0110Y0000000000000", "type": "User", "userOrGroupId": "0050Y0000000000000" }, { "queueId": "00G0Y0000011111111", "queueMemberId": "0110Y000001q5sUQAQ", "type": "Group", "userOrGroupId": "00G0Y000001inOQUAY" } ], "supportedSObjectNames": [ "Case", "Lead" ] }