Retrieve, update, and delete entities
Applies To: Dynamics CRM 2013
This topic shows how to retrieve, update, and delete an entity by using the custom Bank Account entity created in Create a custom entity.
In This Topic
Retrieve and update an entity
Delete a custom entity
Retrieve and update an entity
The following sample retrieves an entity by using the RetrieveEntityRequest message. It then updates the entity to disable mail merge by setting the IsMailMergeEnabled property to false, and sets HasNotes to true in the UpdateEntityRequest to specify that the entity should include a relationship to the Annotation entity so that the entity can display notes.
RetrieveEntityRequest retrieveBankAccountEntityRequest = new RetrieveEntityRequest
{
EntityFilters = EntityFilters.Entity,
LogicalName = _customEntityName
};
RetrieveEntityResponse retrieveBankAccountEntityResponse = (RetrieveEntityResponse)_serviceProxy.Execute(retrieveBankAccountEntityRequest);
EntityMetadata BankAccountEntity = retrieveBankAccountEntityResponse.EntityMetadata;
// Disable Mail merge
BankAccountEntity.IsMailMergeEnabled = new BooleanManagedProperty(false);
// Enable Notes
UpdateEntityRequest updateBankAccountRequest = new UpdateEntityRequest
{
Entity = BankAccountEntity,
HasNotes = true
};
_serviceProxy.Execute(updateBankAccountRequest);
Dim retrieveBankAccountEntityRequest As RetrieveEntityRequest = New RetrieveEntityRequest With {
.EntityFilters = EntityFilters.Entity,
.LogicalName = _customEntityName
}
Dim retrieveBankAccountEntityResponse As RetrieveEntityResponse = CType(_serviceProxy.Execute(retrieveBankAccountEntityRequest), RetrieveEntityResponse)
Dim BankAccountEntity As EntityMetadata = retrieveBankAccountEntityResponse.EntityMetadata
' Disable Mail merge
BankAccountEntity.IsMailMergeEnabled = New BooleanManagedProperty(False)
' Enable Notes
Dim updateBankAccountRequest As UpdateEntityRequest = New UpdateEntityRequest With {
.Entity = BankAccountEntity,
.HasNotes = True
}
_serviceProxy.Execute(updateBankAccountRequest)
Delete a custom entity
The following sample uses the DeleteEntityRequest message to delete the entity with the logical name specified by the _customEntityName variable.
DeleteEntityRequest request = new DeleteEntityRequest()
{
LogicalName = _customEntityName,
};
_serviceProxy.Execute(request);
Dim request As New DeleteEntityRequest() With {.LogicalName = _customEntityName}
_serviceProxy.Execute(request)
See Also
Use the sample and helper code
Customize entity metadata
Create and update an entity than can be emailed
Create a custom entity