Skip to main content
Rakesh K fragte in #Apex
I have created one custom object named as "project"(child) which contains one field of type lookup field named as "Contact Name".I would like to get the reltionshipname of that field. I expected it shuold be its parent object(contact) like standard object. but I am getting the relationshiptype like this Contact_Name__r. I know this one is the default behaviour of custom relationship.But I am trying to get the parent objcet from lookup field,please help me out to get the parent object from other solutions.
1 Antwort
  1. 18. Dez. 2015, 16:03
    Typically the relationship name is just the field name with __c replaced with __r.  You can get the relationship name from the MetadataAPI [1] or by using the describe on the field [2].

    [1] https://developer.salesforce.com/blogs/developer-relations/2015/02/using-metadata-api-describe-objects.html

    [2] https://developer.salesforce.com/docs/atlas.en-us.apexcode.meta/apexcode/apex_methods_system_fields_describe.htm⌗apex_Schema_DescribeFieldResult_getRelationshipName