Skip to main content

Notifications

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

  • Community Member Profile Picture
    on at
    RE: Object reference not set to an instance of an object plugin(Create message-post operation plugin) Error

    c

  • Community Member Profile Picture
    on at
    RE: Object reference not set to an instance of an object plugin(Create message-post operation plugin) Error

    Sorry for typo , i'll send the actual code

  • Suggested answer
    Pradeep Rai Profile Picture
    5,487 Super User 2025 Season 1 on at
    RE: Object reference not set to an instance of an object plugin(Create message-post operation plugin) Error

    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

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

Jainam Kothari – Community Spotlight

We are honored to recognize Jainam Kothari as our June 2025 Community…

Congratulations to the May Top 10 Community Leaders!

These are the community rock stars!

Announcing the Engage with the Community forum!

This forum is your space to connect, share, and grow!

Leaderboard > Customer experience | Sales, Customer Insights, CRM

#1
Daivat Vartak (v-9davar) Profile Picture

Daivat Vartak (v-9d... 671 Super User 2025 Season 1

#2
Vahid Ghafarpour Profile Picture

Vahid Ghafarpour 167 Super User 2025 Season 1

#3
Muhammad Shahzad Shafique Profile Picture

Muhammad Shahzad Sh... 138 Most Valuable Professional

Product updates

Dynamics 365 release plans