locked
Plugin on account entity RRS feed

  • Question

  • write a plugin on account entity and It should check if there is any other account already existing with the same name. System should not allow the creation of duplicate accounts with the same name. Make sure you are including all edge cases.

    can u plz help me out

    Thursday, March 13, 2014 11:21 AM

All replies

  • Hi hiteksha,

    If you're using Dynamics CRM 2011, I suggest using the duplicate detection rule for this. You wouldn't need to code. However, if you're using CRM 2013, then only a Plugin can meet your requirement. Just to give you a outline of what you need to code inside the plugin:

    1. You need to register the plugin in the Create event in the Pre Stage of Account entity.

    2. Inside the Plugin code, retrieve the first and last name of the record (account). You will get this from the context itself.

    3. Make a RetrieveMultiple query by providing filter criteria with first and last name of the account (you got from context) and see if you have any records.

    4. If you have any records, throw an uncaught exception with a message like "Unable to create Account. An Account with the same name already exists". If you don't have any records from the result, no need to do anything and the Account record will be created.


    Admin QuikView Solution for CRM 2013

    Thursday, March 13, 2014 11:34 AM
  • You can also make use of the RetrieveDuplicatesRequest message to programmatically identify duplicates. This message performs duplicate search based on the dupe detection rules registered in CRM. This way it gives you options to add/edit duplicate detection rules without having to modify your code.

    HTH

    Sam


    Dynamics CRM MVP | Inogic | http://inogic.blogspot.com| news at inogic dot com

    If this post answers your question, please click "Mark As Answer" on the post and "Mark as Helpful"

    • Proposed as answer by Sam - Inogic Thursday, March 13, 2014 12:16 PM
    Thursday, March 13, 2014 12:16 PM