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

Notifications

Announcements

No record found.

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

Responsible AI policies

As AI tools become more common, we’re introducing a Responsible AI Use…

Neeraj Kumar – Community Spotlight

We are honored to recognize Neeraj Kumar as our Community Spotlight honoree for…

Leaderboard > Customer experience | Sales, Customer Insights, CRM

#1
Tom_Gioielli Profile Picture

Tom_Gioielli 74 Super User 2025 Season 2

#2
Daniyal Khaleel Profile Picture

Daniyal Khaleel 32 Most Valuable Professional

#3
Gerardo Rentería García Profile Picture

Gerardo Rentería Ga... 31 Most Valuable Professional

Last 30 days Overall leaderboard

Product updates

Dynamics 365 release plans