Hello Community,
protected void ExecutePreStakeholderUpdate(LocalPluginContext localContext) { if (localContext == null) { throw new ArgumentNullException("localContext"); } var context = localContext.PluginExecutionContext; var service = localContext.OrganizationService; // The InputParameters collection contains all the data passed in the message request. if (context.InputParameters.Contains("Target") && context.InputParameters["Target"] is Entity) { // Obtain the target entity from the input parameters. Entity stakeholder = (Entity)context.InputParameters["Target"]; var stakeholderEntity = service.Retrieve("new_stakeholder", stakeholder.Id, new ColumnSet("new_projects", "new_stakeholders")); var projectId = stakeholder.Contains("new_projects") ? stakeholder.GetAttributeValue<EntityReference>("new_projects").Id : (stakeholderEntity.Contains("new_projects") ? stakeholderEntity.GetAttributeValue<EntityReference>("new_projects").Id : Guid.Empty ); var companyId = stakeholder.Contains("new_stakeholders") ? stakeholder.GetAttributeValue<EntityReference>("new_stakeholders").Id : (stakeholderEntity.Contains("new_stakeholders") ? stakeholderEntity.GetAttributeValue<EntityReference>("new_stakeholders").Id : Guid.Empty); Entity project = service.Retrieve("opportunity", projectId, new ColumnSet("name")); Entity company = service.Retrieve("account", companyId, new ColumnSet("name")); var projectName = project != null && project.Contains("name") ? project.GetAttributeValue<string>("name") : string.Empty; var companyName = company.Contains("name") ? company.GetAttributeValue<string>("name") : string.Empty; if (!string.IsNullOrEmpty(projectName) && !string.IsNullOrEmpty(companyName)) { var name = projectName + " - " + companyName; var mobileName = stakeholder.Contains("new_name") ? stakeholder.GetAttributeValue<string>("new_name") : string.Empty; if (mobileName != name) { stakeholder["new_name"] = name; } } } }
The above code raise a NullReferenceException, I dont why or when, the error has been catched on the servers logs. Y only guess is this line of code (the company object) :
commpanyName = company.Contains("name") ? company.GetAttributeValue<string>("name") : "";
Am I missing anything else?
*This post is locked for comments