Wednesday, August 30, 2023

Find a child relationship by name in Salesforce

 This Apex snippet is useful if your deployment fails with "relationship already exist" - usually it's not straightforward to find relationships from the parent side (this sounds like some kind of bad social advice 😂).  I got the idea from a post on StackExchange (forgot to save the reference, dang), and adapted it a little.


DescribeSObjectResult describe = SObjectType.Account;
for (ChildRelationship relation : describe.getChildRelationships())
{
    if(relation.getRelationshipName()=='Bill_Line_Items__r') system.debug(relation);
}

No comments:

Post a Comment