Sometimes due to certain requirements, we are asked to get the Metadata of certain Entities. As this request can hit the performance of our organization, we have to manage this type of requests with caution as well as specifying the total information we want to get. To do the request and to specify the metadata to be retrieved, we have several options that I describe below:
// Entity Metadata Request. RetrieveEntityRequest Request = new RetrieveEntityRequest(); /* * EntityFilters property will allow us to define the * Metadata of the Entity we want to get, we have 5 options: * 1. Entity - Get only Entity information * 2. Attributes - Get Entity and Attributes information * 3. Privileges - Get Entity information and privileges for the Entity * 4. Relationships - Get Entity information and relationships of the Entity * 5. All - Get all data of the Entity */ Request.EntityFilters = EntityFilters.All; // LogicalName property is to define the Entity we want to retrieve Request.LogicalName = "ENTITY_NAME"; // Set True if you want to get unpublished metadata of the entity. Otherwise, set False. Request.RetrieveAsIfPublished = true; // Excecute and save response RetrieveEntityResponse Response = (RetrieveEntityResponse)orgService.Execute(Request);
The most important property in the code above is EntityFilters as this will restrict the total information we’ll get. Make sure to configure it properly based on your requirement.
Let me know any questions!