3
To delete a contact record from the Marketing List table using a plugin in a CMS development services Dubai scenario, follow these steps:
- Retrieve the contact record from the Marketing List table based on specific criteria.
- Use the retrieved record's unique identifier to locate and remove it from the Marketing List table.
- Implement error handling to ensure the deletion process executes smoothly.
- Test the plugin thoroughly to validate its functionality within the CMS development services Dubai environment.
- Deploy the plugin to effectively manage contact records in the Marketing List table.
3
If the Delete message is not working for disassociating contacts from a Marketing List table, it's possible that there might be an issue with the plugin registration, the code logic, or the context in which the plugin is executing. Here are some troubleshooting steps you can follow:
-
Verify Plugin Registration:
- Ensure that the plugin assembly and steps are correctly registered in the Dynamics 365 environment using the Plugin Registration Tool or any other registration method you prefer.
- Check that the plugin step is registered for the PreOperation of the Delete message on the Contact entity.
-
Debugging Plugin Code:
- Add logging statements or use the tracing service to log information about the execution of your plugin. This will help you identify any errors or unexpected behavior.
- Use try-catch blocks to catch any exceptions and log them for troubleshooting purposes.
-
Verify Plugin Execution Context:
- Ensure that the plugin is triggered under the appropriate conditions. For example, verify that the Delete message is indeed being triggered on the Contact entity.
- Check if the plugin is executing in the expected order in the plugin pipeline. You might need to adjust the execution order if necessary.
-
Check Security Roles and Permissions:
- Ensure that the user context under which the plugin is executing has the necessary permissions to disassociate contacts from Marketing Lists.
- Verify that the user has appropriate privileges to read and update Marketing List records.
-
Review Code Logic:
- Double-check your code logic to ensure that it correctly retrieves the Marketing List record and removes the contact from it using the appropriate method (
RemoveMemberFromList
or Disassociate
).
- Make sure that you are passing the correct IDs and entity references when disassociating the contact from the Marketing List.
-
Test Manually:
- Test the disassociation process manually in the Dynamics 365 environment to see if it works as expected. This can help you isolate whether the issue is specific to the plugin or if there are other factors involved.
-
Consult Documentation and Community:
- Refer to the official Microsoft Dynamics 365 documentation and community forums for additional guidance and troubleshooting tips.
- Consider reaching out to the Dynamics 365 support team or community for assistance if you are unable to resolve the issue.
By following these steps and thoroughly investigating the potential causes of the issue, you should be able to identify and resolve any issues preventing the Delete message from correctly disassociating contacts from the Marketing List table.

2
Hi,
To delete a contact record from the Marketing List table using a plugin in Dynamics 365, you need to write a custom plugin that triggers on the deletion of contact records and removes the corresponding record from the Marketing List table. Here's a general outline of how you can achieve this:
1.Create a Plugin: First, create a plugin assembly using Visual Studio or any other preferred development tool.
2.Register the Plugin: Register the plugin on the Delete event of the Contact entity.
3.Retrieve Marketing List Records: In your plugin code, retrieve the Marketing List records that contain the deleted contact. You can do this by querying the Marketing List entity using the contact's ID.
4.Remove Contact from Marketing List: Once you have retrieved the Marketing List records, remove the contact from each of these lists.
5.Update Marketing List Records: Update the Marketing List records in Dynamics 365 to reflect the removal of the contact.
Below the sample code,
using Microsoft.Xrm.Sdk;
using Microsoft.Xrm.Sdk.Query;
using System;
namespace DeleteContactFromMarketingList
{
public class DeleteContactFromMarketingList : IPlugin
{
public void Execute(IServiceProvider serviceProvider)
{
IPluginExecutionContext context = (IPluginExecutionContext)serviceProvider.GetService(typeof(IPluginExecutionContext));
IOrganizationServiceFactory serviceFactory = (IOrganizationServiceFactory)serviceProvider.GetService(typeof(IOrganizationServiceFactory));
IOrganizationService service = serviceFactory.CreateOrganizationService(context.UserId);
if (context.InputParameters.Contains("Target") && context.InputParameters["Target"] is Entity)
{
Entity entity = (Entity)context.InputParameters["Target"];
// Check if the deleted entity is a Contact
if (entity.LogicalName == "contact")
{
Guid contactId = entity.Id;
// Query to retrieve Marketing List records containing the deleted contact
QueryExpression query = new QueryExpression("list");
query.ColumnSet = new ColumnSet("listid");
query.Criteria.AddCondition(new ConditionExpression("createdfromcode", ConditionOperator.Equal, 2)); // Marketing List created from Contacts
query.LinkEntities.Add(new LinkEntity("list", "listmember", "listid", "listid", JoinOperator.Inner));
query.LinkEntities[0].LinkCriteria.AddCondition(new ConditionExpression("entityid", ConditionOperator.Equal, contactId));
EntityCollection marketingLists = service.RetrieveMultiple(query);
// Remove contact from each Marketing List
foreach (var list in marketingLists.Entities)
{
service.Delete("listmember", new Guid(list["listmemberid"].ToString()));
}
}
}
}
}
}
