deleting entity rows using crm sdk 4.0 RRS feed

  • Question

  • I have an account that points to a bunch of rows in a different entity 'abc'. I need to delete those rows in entity 'abc' then insert new ones. Can anyone provide a sample code of how to delete all rows for a particular accountid (which is also a column in the 'abc' entity). Thanks so much.
    Wednesday, August 11, 2010 3:56 PM


  • Try to use following code:

                    QueryByAttribute query = new QueryByAttribute();

                    query.Attributes = new string[] { <account lookup field> };
                    query.ColumnSet = new AllColumns();
                    query.EntityName = <you abc entity name>;
                    query.Values = new object[] { <your account identifier> };

                    RetrieveMultipleRequest request = new RetrieveMultipleRequest();
                    request.Query = query;
                    request.ReturnDynamicEntities = true;

                    List<BusinessEntity> abcs = ((RetrieveMultipleResponse)crmservice.Execute(request)).BusinessEntityCollection.BusinessEntities;

                        foreach (DynamicEntity de in abcs)
                            crmservice.Delete(<you abc entity name>, ((Key)de[<you abc's key field name>]).Value);

    Microsoft CRM Freelancer

    My blog (english)
    Мой блог (русскоязычный)
    • Marked as answer by Barucho1 Wednesday, August 11, 2010 9:05 PM
    Wednesday, August 11, 2010 4:01 PM