• Question

  • when ever deactivating a record of account if account having the opportunity if any one opportunity the open status, i donnot want to deactivate tmy account  through plugin.
    Tuesday, November 14, 2017 1:25 PM

All replies

  • I suggest you a pre-validation plugin if you implement a plugin for validation of a account record.

    https://msdn.microsoft.com/en-us/library/gg327941.aspx#Pipeline stages



    Monday, December 4, 2017 2:54 AM
  • Hello, 

    you can use the below code in your plugin - and register the plugin on both SetState and SetStatedynamicEntity as two different steps.

                string openOpportunity_count = @"<fetch version='1.0' output-format='xml-platform' mapping='logical' distinct='false'>
                                                          <entity name='opportunity'>
                                                            <attribute name='opportunityid' />
                                                            <filter type='and'>
                                                              <condition attribute='statecode' operator='eq' value='0' />
                                                              <condition attribute='parentaccountid' operator='eq' value='[account_GUID]' />
                EntityCollection openOpportunity_count_result = _service.RetrieveMultiple(new FetchExpression(openOpportunity_count));
                if (openOpportunity_count_result.Entities.Count > 0)
                    throw new InvalidPluginExecutionException("The account cannot be deactivated because there are open Opportunities against it.");

    Thanks and Regards.

    • Proposed as answer by Ravitheja J Monday, December 4, 2017 8:23 AM
    Monday, December 4, 2017 8:23 AM