web
You’re offline. This is a read only version of the page.
close
Skip to main content

Announcements

News and Announcements icon
Community site session details

Community site session details

Session Id :
Customer experience | Sales, Customer Insights,...
Suggested Answer

Object reference not set to an instance of an object plugin(Create message-post operation plugin) Error

(0) ShareShare
ReportReport
Posted on by

Entity

I have the same question (0)
  • Suggested answer
    Pradeep Rai Profile Picture
    5,489 Moderator on at

    Hi,

    As per comment f1 is lookup of Entity B but in code you have used f1 has money.

    Also, please below highlighted part as f3 declaration seems to be missing;

    using System;
    using Microsoft.Xrm.Sdk;
    using Microsoft.Xrm.Sdk.Query;
    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Text;


    namespace Acc
    {
    public class Acc : IPlugin
    {
    public void Execute(IServiceProvider serviceProvider)
    {

    #region srvc
    IPluginExecutionContext context = (IPluginExecutionContext)serviceProvider.GetService(typeof(IPluginExecutionContext));
    IOrganizationServiceFactory serviceFactory = (IOrganizationServiceFactory)serviceProvider.GetService(typeof(IOrganizationServiceFactory));
    IOrganizationService service = serviceFactory.CreateOrganizationService(context.UserId);
    ITracingService tracingService = (ITracingService)serviceProvider.GetService(typeof(ITracingService));

    #endregion

    tracingService.Trace("Message from tracing Plugin.. step 1");
    if (context.InputParameters.Contains("Target") && context.InputParameters["Target"] is Entity && context.Depth == 1)
    {
    Entity A = (Entity)context.InputParameters["Target"];
    if (A.LogicalName == "A_name")
    {


    try
    {
    if (A.Attributes.Contains("f1") && A.Attributes.Contains("f2"))
    {
    decimal f1 = (A.Attributes.Contains("f1")) ? A.GetAttributeValue<Money>("f1").Value : 0;
    Guid f2 = (A.Attributes.Contains("f2")) ? A.GetAttributeValue<EntityReference>("f2").Id : Guid.Empty;
    // condition 1
    if (f1 == 0 && f2 != null)
    {
    Entity C = service.Retrieve("c_name", f2, new ColumnSet("f5", "f3"));
    int f5 = (C.Attributes.Contains("f5")) ? C.GetAttributeValue<OptionSetValue>("f5").Value : 0;
    Guid custid = (C.Attributes.Contains("f3")) ? C.GetAttributeValue<EntityReference>("f3").Id : Guid.Empty;
    if (f3 == 804020006) //f3 declaration missing in code
    {
    Entity acc = service.Retrieve("account", custid, new ColumnSet("f4"));
    if (acc.Attributes.Contains("f4") && acc["f4"] != null)
    {
    acc["f4"] = true;
    service.Update(acc);
    }
    }
    }

    catch (Exception ex) { throw new InvalidPluginExecutionException(ex.Message); }

    }


    }
    }
    }
    }

    Also, for better development experience please add multiple tracing inside code.

    Thanks,
    Pradeep

  • Community Member Profile Picture
    on at

    Sorry for typo , i'll send the actual code

  • Community Member Profile Picture
    on at

    c

Under review

Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.

Helpful resources

Quick Links

Season of Sharing Community Challenge Winners!

Congratulations to our community stars!

Women in Power Builds Momentum

Expanding mentorship, skilling, and AI innovation

Congratulations to the June Top 10 Community Leaders

These are the community rock stars!

Leaderboard > Customer experience | Sales, Customer Insights, CRM

#1
Manoj - ManoVerse Profile Picture

Manoj - ManoVerse 131 Super User 2026 Season 1

#2
11manish Profile Picture

11manish 88

#3
Chris1968 Profile Picture

Chris1968 20

Last 30 days Overall leaderboard

Product updates

Dynamics 365 release plans