Skip to main content

Notifications

Announcements

No record found.

Community site session details

Community site session details

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

Best pratices with plugins

(0) ShareShare
ReportReport
Posted on by 5

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?

  • Suggested answer
    Pradeep Rai Profile Picture
    5,482 Super User 2025 Season 1 on at
    RE: Best pratices with plugins

    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.

  • Suggested answer
    Michel Gueli Profile Picture
    982 on at
    RE: Best pratices with plugins

    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();
                }
            }
        }

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

Daivat Vartak – Community Spotlight

We are honored to recognize Daivat Vartak as our March 2025 Community…

Announcing Our 2025 Season 1 Super Users!

A new season of Super Users has arrived, and we are so grateful for the daily…

Kudos to the February Top 10 Community Stars!

Thanks for all your good work in the Community!

Leaderboard

#1
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 293,274 Super User 2025 Season 1

#2
Martin Dráb Profile Picture

Martin Dráb 231,933 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156 Moderator

Leaderboard

Featured topics

Product updates

Dynamics 365 release plans