Skip to main content

Notifications

Microsoft Dynamics CRM (Archived)

Create a custom entity record on delete step of account record in c# plugin..

Posted on by 306

i want to create a custom entity record when  a account record is deleted..

code which i wrote  is not showing any error ,

if (context.MessageName == "Delete")
{

IOrganizationServiceFactory serviceFactory1 = (IOrganizationServiceFactory)serviceProvider.GetService(typeof(IOrganizationServiceFactory));

IOrganizationService service1 = serviceFactory1.CreateOrganizationService(context.UserId);

Entity archieveentity = new Entity("new_archieve");

archieveentity["new_accountnumber"] = "TEST PLUGIN";

service1.Create(archieveentity);

}

If there is  something wrong with code ??

Thanks.

*This post is locked for comments

  • Aric Levin Profile Picture
    Aric Levin 30,188 on at
    RE: Create a custom entity record on delete step of account record in c# plugin..

    Are you getting any error back when you click the Delete?

    Can you possibly share a screenshot of the Plugin Registration Tool of the Delete Message?

    Are there any required fields in the Archive Entity besides account number?

    Do you know if you are actually hitting the code inside the context.MessageName == Delete

  • Aman Anvaria Profile Picture
    Aman Anvaria 306 on at
    RE: Create a custom entity record on delete step of account record in c# plugin..

    Plug-in contains three steps:

    Create

    Update

    Delete

    Create and update were working fine as expected but the problem was with delete step, it was not getting triggered .

    The code which i posted was just a sample of what i actually  want to do.

    At the end i found the solution.

    Thank you Alex for your time and help.

  • ashlega Profile Picture
    ashlega 34,475 on at
    RE: Create a custom entity record on delete step of account record in c# plugin..

    And, also, I would still suggest doing a bit of tracing. Throw an exception from outside that if statement, and, if you see it, do the same from inside if.. just so you knew whether the code is hitting that service1.Create

    You don't have nay plugins on the create of new_archieve entity by any chance? I'm assuming you are trying to find that newly created record and you don't see it.. Is it possible another plugin/workflow would update the name or deactivate that new record so you would not see it in the view?

  • ashlega Profile Picture
    ashlega 34,475 on at
    RE: Create a custom entity record on delete step of account record in c# plugin..

    This code works totally fine when I'm using "contact" entity in place of that new_archieve entity.

    Did you use plugin registration tool to register the plugin? Could you post a screenshot of how it's registered?

    Is there any other code there or it is all you have in the plugin?

  • Aman Anvaria Profile Picture
    Aman Anvaria 306 on at
    RE: Create a custom entity record on delete step of account record in c# plugin..

    It is a Pre-operation plug-in so i can't make it sync or async..

    Thanks

  • ashlega Profile Picture
    ashlega 34,475 on at
    RE: Create a custom entity record on delete step of account record in c# plugin..

    Is it a synchronous pugin or is it an async plugin? If it's async, did you check for any errors in the system jobs log?

    I would also make sure the plugin triggers at all (maybe make it a sync plugin and throw an exception just before that "If"

  • Aman Anvaria Profile Picture
    Aman Anvaria 306 on at
    RE: Create a custom entity record on delete step of account record in c# plugin..

    Yes, i have registered the plugin. When i am deleting the account record it is not creating a record of custom entity.

  • ashlega Profile Picture
    ashlega 34,475 on at
    RE: Create a custom entity record on delete step of account record in c# plugin..

    Hi,

       is it not working? Have you registered the plugin?

Under review

Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.

Helpful resources

Quick Links

December Spotlight Star - Muhammad Affan

Congratulations to a top community star!

Top 10 leaders for November!

Congratulations to our November super stars!

Community AMA December 12th

Join us as we continue to demystify the Dynamics 365 Contact Center

Leaderboard

#1
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 291,240 Super User 2024 Season 2

#2
Martin Dráb Profile Picture

Martin Dráb 230,149 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156

Leaderboard

Featured topics

Product updates

Dynamics 365 release plans