Delete Message (CrmService)
![]() |
[Applies to: Microsoft Dynamics CRM 4.0]
Find the latest SDK documentation: CRM 2015 SDK
| Works for all deployment types | Works online and offline |
Deletes a business entity instance.
The relevant classes are specified in the following table.
| Type | Class |
| Request | DeleteRequest |
| Response | DeleteResponse |
| Target | TargetDelete |
| Entity | See the following table. |
The following table shows the entities and target classes for this message.
Remarks
To use this message, pass an instance of the DeleteRequest class as the request parameter in the Execute method.
When an entity instance is deleted, all child objects of the instance are also deleted. The entire deletion fails if the caller does not have the delete privilege for any of these child objects.
For a description of how actions on a parent instance affect child instances, see Cascading Rules.
To perform this action, the caller must have access rights on the entity instance specified in the request class. For a list of required privileges, see Delete Privileges.
For better performance, use the Delete method instead of using this message.
Example
The following code example demonstrates how to delete a business entity instance.
[C#]
// Set up the CRM Service.
CrmAuthenticationToken token = new CrmAuthenticationToken();
// You can use enums.cs from the SDK\Helpers folder to get the enumeration for Active Directory authentication.
token.AuthenticationType = 0;
token.OrganizationName = "AdventureWorksCycle";
CrmService service = new CrmService();
service.Url = "http://<servername>:<port>/mscrmservices/2007/crmservice.asmx";
service.CrmAuthenticationTokenValue = token;
service.Credentials = System.Net.CredentialCache.DefaultCredentials;
// Create the target object for the request.
TargetDeleteAccount target = new TargetDeleteAccount();
// EntityId is the GUID of the record being deleted.
target.EntityId = new Guid("2B951FBC-1C56-4430-B23B-20A1349068F3");
// Create the request object.
DeleteRequest delete = new DeleteRequest();
delete.Target = target;
// Execute the request.
DeleteResponse deleted = (DeleteResponse)service.Execute(delete);
[Visual Basic .NET]
' Set up the CRM Service.
Dim token As New CrmAuthenticationToken()
' You can use enums.cs from the SDK\Helpers folder to get the enumeration for Active Directory authentication.
token.AuthenticationType = 0
token.OrganizationName = "AdventureWorksCycle";
Dim service As New CrmService()
service.Url = "http://<servername>:<port>/mscrmservices/2007/crmservice.asmx";
service.CrmAuthenticationTokenValue = token;
service.Credentials = System.Net.CredentialCache.DefaultCredentials
' Create the target object for the request.
Dim target As New TargetDeleteAccount()
' EntityId is the GUID of the record being deleted.
target.EntityId = New Guid("2B951FBC-1C56-4430-B23B-20A1349068F3");
' Create the request object.
Dim delete As New DeleteRequest()
delete.Target = target
' Execute the request.
Dim deleted As DeleteResponse = CType(service.Execute(delete), DeleteResponse)
See Also
Reference
.gif)