SLAM_metadata_relationships
Overview
Retrieves Salesforce object relationship definitions to table METADATA_RELATIONSHIPS.
Each row represents a parent-child relationship between two Salesforce objects, including the lookup or master-detail field that defines the relationship.
A relationship record describes a single directional link from a child object to a parent object through a specific field. For example, the standard lookup from Contact.AccountId to Account produces a relationship record with:
ChildSobject.QualifiedApiName=ContactParentSobject.QualifiedApiName=AccountField.QualifiedApiName=AccountIdRelationshipName=Contacts(the name used in SOQL relationship traversal)
Parameters
| Name | Type | Default | Description |
|---|---|---|---|
@exists_action | VARCHAR(20) | NULL | Controls the behavior when the destination table METADATA_RELATIONSHIPS already exists. If NULL, uses the value from SLAM_Settings.default_exists_action (defaulted to 'drop' during initial setup).Valid options:
|
Output Table
Results are written to METADATA_RELATIONSHIPS. The table is created automatically if it does not exist.
| Column | Description |
|---|---|
Id | Salesforce internal record identifier |
DurableId | Stable composite identifier in the format ParentSobjectId.ChildSobjectId.FieldId |
ParentSobjectId | Salesforce internal identifier for the parent object (e.g. Account, but custom objects return a Salesforce Id) |
ParentSobject.QualifiedApiName | API name of the parent object - this is usually what you want (e.g. Custom_Parent_Object__c) |
ChildSobjectId | Salesforce internal identifier for the child object (e.g. Contact, but custom objects return a Salesforce Id) |
ChildSobject.QualifiedApiName | API name of the child object - this is usually what you want (e.g. Custom_Child_Object__c) |
FieldId | Salesforce internal identifier for the lookup/master-detail field |
Field.QualifiedApiName | API name of the field on the child object that holds the relationship - this is usually what you want (e.g. Custom_Lookup_Field__c) |
RelationshipInfoId | Composite identifier for the relationship metadata |
RelationshipName | The SOQL relationship name used for traversal (e.g. Contacts). NULL for system-managed relationships that are not traversable via SOQL |
IsCascadeDelete | 1 if deleting the parent record also deletes child records (master-detail behavior) |
IsDeprecatedAndHidden | 1 if the relationship is object is unavailable for the current version |
IsRestrictedDelete | 1 if the parent record cannot be deleted while child records exist |
JunctionIdListNames | The names of the lists of junction IDs associated with an object. Each ID represents an object that has a relationship with the associated object. |
RelationshipName is the name you use in SOQL dot-notation queries. For example, a relationship with RelationshipName = 'Contacts' on the Account object allows queries like:
-- SOQL
SELECT Id, Name, (SELECT Id, FirstName FROM Contacts) FROM Account
Rows where RelationshipName is NULL are system-managed relationships (such as Owner, CreatedBy) and are not directly traversable using the child-relationship syntax.
Usage Examples
Retrieve all relationships in the org:
EXEC dbo.SLAM_metadata_relationships;
SELECT * FROM METADATA_RELATIONSHIPS;
Find all child objects of Account:
EXEC dbo.SLAM_metadata_relationships;
SELECT
[ChildSobject.QualifiedApiName] AS ChildObject,
[Field.QualifiedApiName] AS LookupField,
RelationshipName
FROM METADATA_RELATIONSHIPS
WHERE [ParentSobject.QualifiedApiName] = 'Account'
ORDER BY [ChildSobject.QualifiedApiName];
Find all parent objects that a Contact references:
SELECT
[ParentSobject.QualifiedApiName] AS ParentObject,
[Field.QualifiedApiName] AS LookupField,
IsCascadeDelete,
IsRestrictedDelete
FROM METADATA_RELATIONSHIPS
WHERE [ChildSobject.QualifiedApiName] = 'Contact'
ORDER BY [ParentSobject.QualifiedApiName];
Refresh with the rename exists action to preserve the previous results:
EXEC dbo.SLAM_metadata_relationships
@exists_action = 'rename';
Related Procedures
- SLAM_describe_objects - retrieves the list of all Salesforce objects and their attributes.
- SLAM_data_dictionary - retrieves detailed field definitions for all (or filtered) objects, including the
ReferenceToattribute that lists the parent objects for each lookup or master-detail field. - SLAM_query_soap - use SOQL dot-notation with relationship names from
METADATA_RELATIONSHIPSto query related fields in a single operation.