i have done these plugin and it's not working
public void Execute(IServiceProvider serviceProvider)
{
// extract the service provider
ITracingService tracingservice = (ITracingService)serviceProvider.GetService(typeof(ITracingService));
IPluginExecutionContext context = (IPluginExecutionContext)serviceProvider.GetService(typeof(IPluginExecutionContext));
IOrganizationServiceFactory srevicefactory = (IOrganizationServiceFactory)serviceProvider.GetService(typeof(IOrganizationServiceFactory));
IOrganizationService service = srevicefactory.CreateOrganizationService(context.UserId);
if(context.InputParameters.Contains("Target")&&context.InputParameters["Target"] is Entity)
{
Entity entity = (Entity)context.InputParameters["Target"];
if (entity.Contains("name"))
{
var fetch = @"<fetch no-lock='true' >
<entity name='opportunity' >
<attribute name='contactid'/>
<filter>
<condition attribute='opportunityid' operator='eq' value='{0}' />
</filter>
</entity>
</fetch>";
var fetchXML = string.Format(fetch, entity.Id);
var allContacts = service.RetrieveMultiple(new FetchExpression(fetchXML)).Entities;
foreach (var contactEnt in allContacts)
{
Entity contactToUpdate = new Entity("opportunityproduct", contactEnt.Id);
contactToUpdate["new_valid_to"] = entity["estimatedclosedate"];
service.Update(contactToUpdate);
}
}
}
}