Partilhar via


IOrganizationService.Delete(String, Guid) Method

Definition

Deletes a record.

public:
 void Delete(System::String ^ entityName, Guid id);
[System.ServiceModel.FaultContract(typeof(Microsoft.Xrm.Sdk.OrganizationServiceFault))]
[System.ServiceModel.OperationContract]
public void Delete (string entityName, Guid id);
[<System.ServiceModel.FaultContract(typeof(Microsoft.Xrm.Sdk.OrganizationServiceFault))>]
[<System.ServiceModel.OperationContract>]
abstract member Delete : string * Guid -> unit
Public Sub Delete (entityName As String, id As Guid)

Parameters

entityName
String

The logical name of the table that is specified in the id parameter.

id
Guid

The ID of the record that you want to delete.

Attributes

Examples

The following example shows four different ways to set the parameters for the Delete(String, Guid) method depending on common ways you might reference a record that you want to delete.

For this sample to work correctly, you must be connected to the server to get an IOrganizationService interface instance.

/// <summary>
/// Demonstrates the Delete method
/// </summary>
/// <param name="service">Authenticated IOrganizationService instance</param>
/// <param name="earlyBoundAccount">An early bound Account instance.</param>
/// <param name="lateBoundAccount">A late bound account Entity record.</param>
/// <param name="accountReference">A reference to an account record.</param>
/// <param name="accountId">The ID of an account record to delete.</param>
static void DeleteAccountsExample(IOrganizationService service,
      Account earlyBoundAccount,
      Entity lateBoundAccount,
      EntityReference accountReference,
      Guid accountId)
{
      // Early bound example
      service.Delete(Account.EntityLogicalName, earlyBoundAccount.Id);
      // Late bound example
      service.Delete(lateBoundAccount.LogicalName, lateBoundAccount.Id);
      // Account reference 
      service.Delete(accountReference.LogicalName, accountReference.Id);
      // Guid ID
      service.Delete("account", accountId);
}

You can find more samples on GitHub:

Remarks

Learn how to delete table rows using the SDK for .NET.

Privileges and Access Rights

To perform this action, the caller must have Delete privileges on the table that is specified in the entityName parameter and Delete access rights on the record that is specified in the id parameter.

When a record is deleted and there are related records in table that has a relationship configured for cascading delete, all child records are also deleted. The entire deletion fails if the caller does not have the Delete privilege or access rights for any of these related records.

Learn more about how to verify access with code.

Learn more about table relationship behavior.

Notes for Callers

Typically, you should only delete records that you entered by mistake. For some tables, you can deactivate the record by updating the statecode attribute to 1, the Inactive state.

For more information about the exceptions that can be thrown when you call this method, see Handle exceptions in your code.

Supported tables

You can use this method to create any record of a table that supports the Delete message. Learn more about Table support for messages and Message support for tables.

Applies to

See also