How it works...

We first started by importing an additional namespace that contains FaultException that we caught in our code.

In step 2, we implemented the IPlugin interface. This interface indicated to Dynamics 365 that this class can execute a plugin and follows the expected plugin signature.

In step 3, we implemented the Execute method required by the IPlugin interface. Within this method, we did some standard checks to ensure that we have the target entity as an input parameter, then we validated that the entity is an account (this is not necessary if we want the plugin to execute on any entity), then we retrieved the organization service that we assigned to a local variable and also instantiated the organization service context class.

The rest of the method contains some business logic and leverages the methods created in the previous recipe to close the e-mails with no subject, and to update the ones with a subject with a new date. Once all e-mails were updated, we committed our changes.

Towards the end of the method, we introduced some error handling to trace and throw exceptions. To display a user-friendly error message, we threw an exception using InvalidPluginExecutionException.

Throwing a sanitized exception message is a good practice to ensure that a user-friendly error message is displayed to the user.
..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
3.21.100.62