locked
Updating Account record from the contact record using plugin in MS CRM 2011 RRS feed

  • Question

  • Hi All,

    I have the requirement to update the respective account record (field:-associated contact lookup value) whenever contact record is update

    using plug-in. Any help greatly appreciated..

    Regards

    Srikanth Reddy



    Saturday, June 7, 2014 6:44 AM

All replies

  • Hi Srikanth,

    You can use Pre or Post message of your contact.This example will set the name to related account.You can set the fields due to your process

    protected void ExecutePreContactUpdate(LocalPluginContext localContext) { if (localContext == null) { throw new ArgumentNullException("localContext"); } IPluginExecutionContext context = localContext.PluginExecutionContext; IOrganizationService service = localContext.OrganizationService;

      Entity entity = (Entity)localContext.PluginExecutionContext.InputParameters["Target"];

    Entity preImageEntity = (context.PreEntityImages != null && context.PreEntityImages.Contains(this.preImageAlias)) ? context.PreEntityImages[this.preImageAlias] : null;

    Entity account = new Entity ();

    account.Id = ((EntityReference)preImageEntity["parentcustomerid"]).Id;

    account["name"] = entity["fullname"];

    service.Update(account);

    }



    Polat Aydın Crm Software Developer


    Saturday, June 7, 2014 9:23 AM