I have a requirement to create new contact every time an account is being created.
However the account must also be updated with the contact as Primary account.
Everything works fine and the contact is created but I get an error to update the account .
The GUID of the contact returned is 00000000-0000-0000-0000-000000000000.
have registered the plugin also in asynchronous mode, but the primary contact is not update on the account.
The plugin is registered on the PostOperation of create account.
I know this can be done easily with a workflow but the requirement is to use a plugin.
try { Entity postImage = (Entity)context.PostEntityImages["PostImage"]; var accountID = postImage.GetAttributeValue<Guid>("accountid"); var companyName = postImage.GetAttributeValue<String>("name"); var companyPhone = postImage.GetAttributeValue<String>("telephone1"); Entity contact = new Entity("contact"); contact["firstname"] = companyName; contact["lastname"] = "Account"; contact["telephone1"] = companyPhone; contact["parentcustomerid"] = new EntityReference("account", accountID); IOrganizationServiceFactory serviceFactory = (IOrganizationServiceFactory)serviceProvider.GetService(typeof(IOrganizationServiceFactory)); IOrganizationService service = serviceFactory.CreateOrganizationService(context.UserId); tracingService.Trace("Plugin: Creating the Contact."); service.Create(contact); Guid contactid = contact.Id; tracingService.Trace("The Contact ID is " +contactid); //checking the contact ID but it returns 000000000000000 Entity account = new Entity("account", accountID); account["primarycontactid"] = new EntityReference("contact", contactid); service.Update(account); // update the primary contact lookup }
*This post is locked for comments