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
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
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.
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?
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?
It is a Pre-operation plug-in so i can't make it sync or async..
Thanks
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"
Yes, i have registered the plugin. When i am deleting the account record it is not creating a record of custom entity.
Hi,
is it not working? Have you registered the plugin?
Stay up to date on forum activity by subscribing. You can also customize your in-app and email Notification settings across all subscriptions.
André Arnaud de Cal... 291,240 Super User 2024 Season 2
Martin Dráb 230,149 Most Valuable Professional
nmaenpaa 101,156