Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7954679
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T03:30:10+00:00 2026-06-04T03:30:10+00:00

I am attempting to create a plugin for an onsite Dynamics CRM 2011 installation.

  • 0

I am attempting to create a plugin for an onsite Dynamics CRM 2011 installation.

I have registered the plugin as follows:

  • Message: Create
  • Primary entity: Contact
  • Stage of execution: Post-operation
  • Execution mode: Synchronous
  • Execution order: 1

Plugin code as follows:

public void Execute(IServiceProvider serviceProvider)
{
    var pluginExecContext = (IPluginExecutionContext)serviceProvider.GetService(typeof(IPluginExecutionContext));

    var orgServiceFactory = (IOrganizationServiceFactory)serviceProvider.GetService(typeof(IOrganizationServiceFactory));
    var orgService = orgServiceFactory.CreateOrganizationService(pluginExecContext.UserId);
    var orgServiceContext = new OrganizationServiceContext(orgService);

    var tracingService = (ITracingService)serviceProvider.GetService(typeof(ITracingService));

    if (pluginExecContext.InputParameters.Contains("Target") &&
            pluginExecContext.InputParameters["Target"] is Entity)
    {
        var target = (Entity)pluginExecContext.InputParameters["Target"];

        if (target.LogicalName != Contact.EntityLogicalName) 
            return;

        try
        {
            var customerServicesUser = orgServiceContext.CreateQuery(SystemUser.EntityLogicalName)
                .Where(x => (string)x["fullname"] == "Customer Services").FirstOrDefault();

            if (customerServicesUser == null)
                throw new InvalidPluginExecutionException("No Customer Services user exists.");

            var sendEmail = new cdi_sendemail
                {
                    cdi_fromrecordowner = false,
                    cdi_contactid = new EntityReference(Contact.EntityLogicalName, pluginExecContext.PrimaryEntityId),
                    cdi_fromid = new EntityReference(SystemUser.EntityLogicalName, customerServicesUser.Id)
                };

            tracingService.Trace("PostContactCreate plug-in: Creating the cdi_sendemail entity.");
            orgService.Create(sendEmail);
        }
        catch (FaultException<OrganizationServiceFault> ex)
        {
            throw new InvalidPluginExecutionException("An error occurred in the PostContactCreate plug-in.", ex);
        }
        catch (Exception ex)
        {
            tracingService.Trace("PostContactCreate plug-in: {0}", ex.ToString());
            throw;
        }
    }
}

When I profile the plugin using the pluginregistration tool and debug the fault exception I get the following error:

Contact With Id = abbc7e0a-20a0-e111-a36e-005056860004 Does Not Exist.

Which I sort of understand as the plugin is executing within a SQL transaction that has yet to commit. The “FollowupPlugin” within the CRM SDK samples, which also creates a referenced entity, states that it needs to be registered asynchronously, which would also make sense as that allows the SQL transaction to commit.

So I guess my question is, how do you create a referenced entity in a synchronous plugin?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-04T03:30:11+00:00Added an answer on June 4, 2026 at 3:30 am

    Looking at the SDK example for a very similar example – I think you need to register in the sandbox.

    Register this plug-in for an account entity, on the Create message, and in asynchronous mode. Alternately, you can register the plug-in on a post-event in the sandbox.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm attempting to create a C++ plugin for a realtime 3D game. Although I
I am attempting to create a jQuery plugin for my own use that can
I'm attempting to create a bare bones app for use in developing a plugin.
I'm attempting to run a rake task through Jenkins. I have the plugin installed.
I'm attempting to write a StructureMap plugin scanner for Payment Gateway implementations. I have
I am attempting to create a custom tableview where I have a list of
I am attempting to create an image gallery. At the bottom I have a
I'm attempting to create a plugin that compares the time of a piece of
Im attempting to create a new operator :? on lists, which operates the same
I attempting to create an 800x500 div with four overlapping divs inside the container

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.