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

Announcements

No record found.

News and Announcements icon
Community site session details

Community site session details

Session Id :
Customer experience | Sales, Customer Insights,...
Answered

Best pratices with plugins

(0) ShareShare
ReportReport
Posted on by 16

Hi there!

I've only one plugin class to Opportunity entity, and updates in different fields triggers different actions of update.

In this plugin class I have a method that is called to any kind of update in Opportunity.

In this method, for example, the sequence below is executed:

samplePlugin.PNG

ActionA() should only be trigged if owner field has been updated and ActionB() should only be trigged if customer field has been updated.

What's the best pratices to do that?

I have the same question (0)
  • Suggested answer
    Michel Gueli Profile Picture
    982 on at

    public class PostOperationOpportuniyUpdate : IPlugin
        {
            public void Execute(IServiceProvider serviceProvider)
            {
                ITracingService trace = (ITracingService)serviceProvider.GetService(typeof(ITracingService));
                IPluginExecutionContext context = (IPluginExecutionContext)serviceProvider.GetService(typeof(IPluginExecutionContext));
                IOrganizationServiceFactory factory = (IOrganizationServiceFactory)serviceProvider.GetService(typeof(IOrganizationServiceFactory));
                IOrganizationService service = factory.CreateOrganizationService(context.UserId);
    
                var opportunity = context.GetTargetEntity();
    
                if (opportunity != null)
                {
                    var opportunityHandler = new OpportunityHandler(service, trace);
    
                    if(opportunity.Contains("ownerid"))
                        opportunityHandler.ActionA();
    
                    if(opportunity.Contains("customerid"))
                        opportunityHandler.ActionB();
                }
            }
        }

  • Verified answer
    Pradeep Rai Profile Picture
    5,489 Moderator on at

    Hi,

    You need to register the steps for records Update.

    In Plugin you can check Target contains the fields or not. Because when records update then Target contains only those fields which was changed by user.

    Thanks.

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

Introducing the 2026 Season 1 community Super Users

Congratulations to our 2026 Super Stars!

Meet the Microsoft Dynamics 365 Contact Center Champions

We are thrilled to have these Champions in our Community!

Congratulations to the March Top 10 Community Leaders

These are the community rock stars!

Leaderboard > Customer experience | Sales, Customer Insights, CRM

#1
ManoVerse Profile Picture

ManoVerse 151 Super User 2026 Season 1

#2
11manish Profile Picture

11manish 134

#3
Jimmy Passeti Profile Picture

Jimmy Passeti 55 Most Valuable Professional

Last 30 days Overall leaderboard

Product updates

Dynamics 365 release plans