Monday, February 27, 2012

Delete an Entity Record in Microsoft Dynamics CRM 2011 Using Silverlight

This tutorial will show you how to delete an entity record in Microsoft Dynamics CRM 2011 using C# in Silverlight.

First things first.  You have to set up your Silverlight app to make a web services connection to CRM.   The best tutorial I have found for this is located here in the MSDN:
http://msdn.microsoft.com/en-us/library/gg594452.aspx

Here is the call in C#:

//delete request
OrganizationRequest request = new OrganizationRequest() { RequestName = "Delete" };
EntityReference entrefDeleteTarget = new EntityReference();
entrefDeleteTarget.Id = new Guid("A42D83C5-5E61-E111-AC43-1CC1DEF1B5FF");
entrefDeleteTarget.LogicalName = "account";
request["Target"] = entrefDeleteTarget;


IOrganizationService service = SilverlightUtility.GetSoapService();

service.BeginExecute(request, new AsyncCallback(AccountDelete_ClickCallback), service);

You will notice that the biggest change in thinking and syntax will be that you have to specify your request and response properties as strings explicitly in code.

- I hope this helps!!

3 comments:

  1. and the method AccountDelete_ClickCallback ?

    ReplyDelete
  2. service.BeginExecute(request, new AsyncCallback(AccountDelete_ClickCallback), service);



    How to make the method AccountDelete_ClickCallback?

    ReplyDelete
    Replies
    1. You just need to define it in code. It would be like:

      private void AccountDelete_ClickCallback(IAsyncResult result)
      {
      }

      I didn't include it because it's more of a generic thing you have to do when making asynchronous calls in .NET

      Delete