DeleteRequest Class

Definition

Contains the data that is needed to delete a record.

public ref class DeleteRequest sealed : Microsoft::Xrm::Sdk::OrganizationRequest
[System.Runtime.Serialization.DataContract(Namespace="http://schemas.microsoft.com/xrm/2011/Contracts")]
public sealed class DeleteRequest : Microsoft.Xrm.Sdk.OrganizationRequest
[<System.Runtime.Serialization.DataContract(Namespace="http://schemas.microsoft.com/xrm/2011/Contracts")>]
type DeleteRequest = class
    inherit OrganizationRequest
Public NotInheritable Class DeleteRequest
Inherits OrganizationRequest
Inheritance
DeleteRequest
Attributes

Examples

The following example shows how to use this message. For this sample to work correctly, you must be connected to the server to get an IOrganizationService interface instance.

The following example demonstrates using optional parameters.

/// <summary>
/// Demonstrates deleting a record with optional parameters
/// </summary>
/// <param name="service">Authenticated IOrganizationService instance</param>
static void DeleteWithOptionalParameters(IOrganizationService service)
{
    Guid accountId = new("8eb3e71c-9a51-ee11-be6f-000d3a993550");

    // Simulate an account record retrieved
    Entity retrievedAccount = new("account", accountId);

    DeleteRequest request = new()
    {
        Target = retrievedAccount.ToEntityReference()
    };

    // Set a shared variable that a plug-in can access
    request["tag"] = "RecordDeletedBySampleCode";
    // Bypass plug-in logic if caller has prvBypassCustomPlugins privilege
    request["BypassCustomPluginExecution"] = true;
    // Don't trigger any flows for this operation
    request["SuppressCallbackRegistrationExpanderJob"] = true;

    service.Execute(request);
}        

For an example showing optimistic concurrency checks see the ConcurrencyBehavior property.

Sample code on GitHub

Use optimistic concurrency with update and delete operations

Remarks

Usage

Pass an instance of this class to the Execute(OrganizationRequest) method, which returns an instance of the DeleteResponse class.

Privileges and Access Rights

To perform this action, the caller must have delete privileges on the table and access rights on the record specified by the Target property. Learn more about how to verify access in code

Notes for Callers

Use this class when you want to:

For a less complex method that deletes a single record, without the ability to manage concurrency or use optional parameters, use the IOrganizationService.Delete method.

When a record is deleted, some related records may also be deleted depending on the cascade configuration for relationships. If the relationship specifies Cascade All for the Delete action, the operation will attempt to delete related records. The entire operation fails if the caller does not have the delete privilege or access rights for any of these records. Learn more about table relationship behavior

Typically, you should only delete records that you entered by mistake. For some record types, you can deactivate or close the record instead.

Supported Tables

See Message support for tables for an example query you can use to get the list of tables you can use with the Delete message.

Constructors

DeleteRequest()

Initializes a new instance of the DeleteRequest class.

Properties

ConcurrencyBehavior

Specifies the type of optimistic concurrency behavior that should be performed by Dataverse when processing this request.

ExtensionData

Gets or sets the structure that contains extra data. Optional.

(Inherited from OrganizationRequest)
Item[String]

Gets or sets the indexer for the Parameters collection.

(Inherited from OrganizationRequest)
Parameters

Gets or sets the collection of parameters for the request. Required, but is supplied by derived classes.

(Inherited from OrganizationRequest)
RequestId

Gets or sets the ID of the request. Optional.

(Inherited from OrganizationRequest)
RequestName

Gets or sets the name of the request. Required, but is supplied by derived classes.

(Inherited from OrganizationRequest)
Target

Gets or sets the reference to the record that you want to delete. Required.

Applies to

See also