IOrganizationService.Execute(OrganizationRequest) Method


Executes a message in the form of a request, and returns a response.

 Microsoft::Xrm::Sdk::OrganizationResponse ^ Execute(Microsoft::Xrm::Sdk::OrganizationRequest ^ request);
public Microsoft.Xrm.Sdk.OrganizationResponse Execute (Microsoft.Xrm.Sdk.OrganizationRequest request);
abstract member Execute : Microsoft.Xrm.Sdk.OrganizationRequest -> Microsoft.Xrm.Sdk.OrganizationResponse
Public Function Execute (request As OrganizationRequest) As OrganizationResponse



A request instance that defines the action to be performed.


The response from the request. If you need to get data from the response class, you must cast the return value of this method to the specific type of the response that corresponds to the Request parameter.



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

The following example shows how to use the Execute(OrganizationRequest) method to use the WhoAmIRequest class and access the data returned with the WhoAmIResponse class. This request has no parameters.

/// <summary>
/// Demonstrates executing a WhoAmI request
/// </summary>
/// <param name="service">Authenticated IOrganizationService instance</param>
static void WhoAmIExample(IOrganizationService service) {

      WhoAmIRequest request = new();
      var response = (WhoAmIResponse)service.Execute(request);

      Console.WriteLine($"UserId: {response.UserId}");
      Console.WriteLine($"OrganizationId: {response.OrganizationId}");
      Console.WriteLine($"BusinessUnitId: {response.BusinessUnitId}");

The following example shows how to use the Execute(OrganizationRequest) method to share a record to a user or team using the GrantAccessRequest class. While a GrantAccessResponse class exists, you don't need to use it because this operation doesn't return any data.

/// <summary>
/// Demonstrates executing a GrantAccess request
/// </summary>
/// <param name="service">Authenticated client implementing the IOrganizationService interface</param>
/// <param name="principal">The user, team, or organization to share the record with.</param>
/// <param name="access">The access rights to grant</param>
/// <param name="record">The record to share</param>
static void GrantAccessExample(
   IOrganizationService service,
   EntityReference principal,
   AccessRights access,
   EntityReference record)
      PrincipalAccess principalAccess = new()
         AccessMask = access,
         Principal = principal

      GrantAccessRequest request = new()
         PrincipalAccess = principalAccess,
         Target = record


Learn more about using sharing and assigning records.


The Execute method is the only method that the Organization service uses. The other IOrganizationService methods are helper methods that instantiate the appropriate AssociateRequest, CreateRequest, DisassociateRequest, RetrieveRequest, RetrieveMultipleRequest, or UpdateRequest class instances and send the request using Execute. Understanding the Execute method is central to understanding how Dataverse data operations work. Learn how to use messages with the SDK for .NET.

Privileges and Access Rights

The privileges and access rights necessary when using the Execute method depend entirely on the nature of the data operation being performed. If the operation creates, updates, or deletes data, the caller must have the appropriate Create, Read, Write, Delete, Append, AppendTo, Assign, or Share privileges on any tables and the access rights on the individual records that the operation is applied to. Learn more about how to verify access with code.

For more information, see the Request class for the action you want to execute. For example, see GrantAccessRequest, or documentation for the message you want to use if you are using the base OrganizationRequest and OrganizationResponse classes.

Notes for Callers

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

Applies to