Code Snippets

  • Execute operations (create, update, delete)
    C#
    This C# snippet demonstrates performing Create, Update, and Delete operations in Dynamics 365 using the SDK
This C# code snippet demonstrates how to perform basic CRUD operations in Dynamics 365. It establishes a connection to the service, creates an account entity, updates its `telephone1` field, and deletes it using its GUID. Customize the URL, entity, and field names based on your Dynamics 365 environment.

using System; using Microsoft.Xrm.Sdk; using Microsoft.Xrm.Sdk.Client; using Microsoft.Xrm.Sdk.Query; class Dynamics365CrudOperations { static void Main(string[] args) { // Connection to Dynamics 365 Uri serviceUri = new Uri("https://.crm.dynamics.com/XRMServices/2011/Organization.svc"); using (OrganizationServiceProxy serviceProxy = new OrganizationServiceProxy(serviceUri, null, null, null)) { IOrganizationService service = (IOrganizationService)serviceProxy; // CREATE Operation Entity newAccount = new Entity("account"); newAccount["name"] = "Sample Account"; Guid accountId = service.Create(newAccount); Console.WriteLine($"Account created with ID: {accountId}"); // UPDATE Operation Entity updateAccount = new Entity("account"); updateAccount.Id = accountId; updateAccount["telephone1"] = "123-456-7890"; service.Update(updateAccount); Console.WriteLine($"Account with ID {accountId} updated."); // DELETE Operation service.Delete("account", accountId); Console.WriteLine($"Account with ID {accountId} deleted."); } } }