protected override void ExecuteInternal(ExtendedPluginContext context) { var preImage = context.GetPreEntity <Contact>(); var target = context.CoalesceTargetWithPreEntity <Contact>(); if (preImage.EMailAddress1 == target.EMailAddress1) { context.Trace("Email Address 1 didn't change. Exiting."); return; } if (target.AccountId == null) { context.Trace("No Account for Contact. Exiting."); return; } InitializeAccount(context, target); if (Account.PrimaryContactId == null) // Account could have been changed by a new thread. { SetContactToPrimary(context); } else if (Account.PrimaryContactId?.Id != context.PrimaryEntityId) // Account could have changed, which could result in this being true, when it shouldn't. { context.Trace("Contact is not primary contact of the account. Exiting."); return; } UpdateAccountEmail(context, target); }
protected override void ExecuteInternal(ExtendedPluginContext context) { // Get the Target var contact = context.GetTarget <Contact>(); if (string.IsNullOrWhiteSpace(contact.Address1_Line1)) { context.Trace(AddressNotUpdatedMessage); return; } using (var crm = new CrmContext(context.OrganizationService)) { var accounts = crm.AccountSet.Where(a => a.PrimaryContactId.Id == contact.Id); foreach (var account in accounts) { UpdateAccountAddress(context.OrganizationService, account.Id, contact); } } }