locked
What's the error in the plugin POST create Opportunity CRM 2011 RRS feed

  • Question

  • My code plugin:

    using System;
    using System.ServiceModel;
    using Microsoft.Xrm.Sdk;
    
    namespace WASKOCRMBB
    {
       public class PostprojektCreate:IPlugin
       {
           public void Execute(System.IServiceProvider serviceProvider)
            {
                try
                {
                    IPluginExecutionContext context = (IPluginExecutionContext)serviceProvider.GetService(typeof(IPluginExecutionContext));
                    IOrganizationServiceFactory serviceFactory = (IOrganizationServiceFactory)serviceProvider.GetService(typeof(IOrganizationServiceFactory));
                    IOrganizationService service = serviceFactory.CreateOrganizationService(context.UserId);
    
                    if (context.InputParameters.Contains("Target") && context.InputParameters["Target"] is Entity)
                    {
    
                        Microsoft.Xrm.Sdk.Entity opportunity = (Entity)context.InputParameters["Target"];
                        try
                        {
                            Microsoft.Xrm.Sdk.Entity m7_osoba = new Entity("m7_osoba");
    
                          
                            Guid EntityId = opportunity.Id;
                            m7_osoba["m7_szansasprzedazyid"] = new EntityReference("opportunity", EntityId);
                          
                            m7_osoba["m7_name"] = "Handlowiec zaangazawany";
                            m7_osoba["m7_udzialwmarzy"] = 100;
                           
                            service.Create(m7_osoba);
                        }
    
                        catch (Exception ex)
                        {
                            throw new Exception("Błąd przy dodawaniu handlowca zaangażowanego:" + ex.Message + "gdzie:" + ex.Source);
                        }
                       
                    }
                }
                catch (Exception ex)
                {
                    throw new Exception("Błąd ogolny:" + ex.Message + "ff:" + ex.Source);
                }
    
                // TODO: Implement your custom Plug-in business logic.
            }
        }
    }

    In CRM gets the error:

    Błąd ogolny:Błąd przy dodawaniu handlowca zaangażowanego:The specified object was not found.gdzie:Microsoft.Crm.Extensibility ff:WASKOCRM2011BB

    Plugin is the creation of a record opportunity to create a record in another entity m7_osoba, combined with opportunityId reference.

    What this plugin is badly?


    • Edited by Barteo Tuesday, April 15, 2014 2:30 PM
    Tuesday, April 15, 2014 2:23 PM

All replies