How to get the related entities of an entity like account or contact in CRM RRS feed

  • Question

  • Hi,

    I am new to CRM. I need to get all entities related to an entity like account or contact. For an account entity the related entities should be Appointments, Campaigns, Cases, Contacts etc.  I am not supposed to add any relationship, just need to retrieve the entities related to account or contact. I tried with below code but in the response object RetrieveAllEntitiesResponse -> results[0]. _relatedentities.  I have a property relatedentities  but the count is 0. Am I missing anything? or do I need add any code to get the related entities?

    RetrieveAllEntitiesRequest retrieveAllEntitiesRequest = new RetrieveAllEntitiesRequest()
        EntityFilters = EntityFilters.Entity | EntityFilters.Privileges | EntityFilters.Relationships,
        RetrieveAsIfPublished = false

    Saturday, July 20, 2013 3:58 PM

All replies

  • The request you are using returns the metadata for CRM entities, not the actual records themselves. See http://msdn.microsoft.com/en-us/library/microsoft.xrm.sdk.messages.retrieveallentitiesrequest.aspx for more information.

    To retrieve all related record for an entity, I suggest writing out separate queries and pass in the GUID of the parent record. You could potentially add these queries into some helper repository which you can then call to get all related records.

    • Proposed as answer by Roshan Mehta Sunday, July 21, 2013 9:44 AM
    Sunday, July 21, 2013 9:44 AM
  • Hi,

    What is the exact requirement to retrieve all related entities? Why you do not query them one by one?

    My Weblog | My Website

    Sunday, July 21, 2013 2:06 PM
  • Hi,

    I just want to display the related entitiy names like accounts, contacts, cases etc not the record.  Based on the entity name need to need to get all related entity names and display it. Please help me out how can i query them one by one?

    Monday, July 22, 2013 4:55 AM
  • Hi,

    I have  followed the link mentioned and RetrieveAllEntitiesResponse.EntityMetadata has related entities property but the count of those records is 0. did i miss anything?


    Monday, July 22, 2013 4:57 AM
  • You will need to write separate queries. E.g if you have an Account called X, you can retrieve related contacts by querying contact records where the parentcustomer is X. There are plenty of tutorials online. Here is an example using QueryExpression.


    • Proposed as answer by Roshan Mehta Monday, July 22, 2013 11:04 AM
    Monday, July 22, 2013 11:04 AM