Retrieve, update, and delete entities

This topic shows how to retrieve, update, and delete an entity by using the custom Bank Account entity created in Create 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


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,

See also

Use the IOrganizationService Sample and Helper Code
Customize entity metadata
Create and update an entity than can be emailed
Create a Custom Entity