Retrieving entity information programmatically

There are times that we need to retrieve information related to an entity separately. For an instance if we want to know the primary key field name in an entity or primary field id (this can be taken using the entityname + “id”) of an entity this is useful. The code snippet needed for this given below.
RetrieveEntityRequest retrieveEntityRequest = new RetrieveEntityRequest
                EntityFilters = EntityFilters.Attributes,
                LogicalName = “contact”

RetrieveEntityResponse retrieveEntityResponse = (RetrieveEntityResponse)Execute(retrieveEntityRequest);

if (retrieveEntityResponse != null)
                return retrieveEntityResponse.EntityMetadata.PrimaryNameAttribute;

The above will return the primary field name of the entity.


Popular posts from this blog

Error message “User does not have send-as privilege.” when sending emails programmatically in CRM 2011