I want to share my contacts to only sales person who belongs to my child BU. I've done so far the following but I thought I am little de-tracked because of not nominating 'Sales Persons' into it. Any idea how can I share contact to my sales persons?
public void Execute(IServiceProvider isp) { IPluginExecutionContext context = (IPluginExecutionContext)isp.GetService(typeof(IPluginExecutionContext)); ITracingService trace = (ITracingService)isp.GetService(typeof(ITracingService)); IOrganizationServiceFactory factoy = (IOrganizationServiceFactory)isp.GetService(typeof(IOrganizationServiceFactory)); IOrganizationService service = factoy.CreateOrganizationService(context.UserId); if (context.InputParameters.Contains("Target") && context.InputParameters["Target"] is Entity) { Entity contect = (Entity)context.InputParameters["Target"]; Guid guid = ((EntityReference)contect.Attributes["createdby"]).Id; var createdReference = new EntityReference("systemuser",guid); var grantAccess = new GrantAccessRequest { PrincipalAccess = new PrincipalAccess { AccessMask = AccessRights.ReadAccess, Principal = createdReference }, Target = new EntityReference("contect",contect.Id), }; service.Execute(grantAccess); } }