Skip to content

MetadataCatalogRecipes

pozil edited this page May 14, 2024 · 12 revisions

MetadataCatalogRecipes

Demonstrates how to query the Metadata Catalog. This is sometimes faster that Schema Describe calls especially for large complex orgs

Group Data Recipes

Methods

public static Map<String,Map<String,String>> findAllFormulaFields()

SUPPRESSWARNINGS

Demonstrates how to query the EntityDefinition Object to find all formula fields in your Org. This method returns a Map of Object's Qualified API name -> Map of Field Names -> Types Note: This method has a false-positive PMD warning. PMD isn't aware of the purpose or functionality of CanTheUser.* so it doesn't undersatnd that we are, in fact, checking for CRUD / FLS permissions prior to querying.

Returns

Type Description
Map<String,Map<String,String>> Map<String, Map<String, String>>

Example

Map<String, Map<String, String>> results =
     MetadataCatalogRecipes.findAllFormulaFields();
System.debug(results);

public static List<MetadataCatalogRecipes.LookupRelationshipDefinition> findAllContactFieldsThatLookupToAccount()

SUPPRESSWARNINGS

Demonstrates how to query the metadata catalog to find all fields on the Contact object that establish a relationship to the Account Object. Note: This method has a false-positive PMD warning. PMD isn't aware of the purpose or functionality of CanTheUser.* so it doesn't undersatnd that we are, in fact, checking for CRUD / FLS permissions prior to querying.

Returns

Type Description
List<MetadataCatalogRecipes.LookupRelationshipDefinition> List<MetadataCatalogRecipes.LookupRelationshipDefinition>

Example

List<MetadataCatalogRecipes.LookupRelationshipDefinition> results =
     MetadataCatalogRecipes.findAllContactFieldsThatLookupToAccount();
System.debug(results);

Classes

LookupRelationshipDefinition

internal data object for information about a Lookup Relationship

Constructors

public LookupRelationshipDefinition(FieldDefinition fd)

Constructor that transforms a Field Definition object into a LookupRelationshipDefinition Object.

Parameters
Param Description
fd a FieldDefinition Object
Example
FieldDefinition fd = [SELECT Id, DeveloperName, RelationshipNme,
                         DataType
                      FROM FieldDefinition LIMIT 1];
MetadataCatalogRecipes.LookupRelationshipDefinition lrd = new
     MetadataCatalogRecipes.LookupRelationshipDefinition(fd);
System.debug(lrd);

Properties

public looksUpToString

Specifies what object this one looks up to

public developerNameString

Specifies the name of the Object

public relationshipNameString

Specifies the Relationship field name

public dataTypeString

Specifies the Data Type Of this Object



Clone this wiki locally