We are adding Contact and sending email in Sitecore 9.1.1. We dont want to show that contact in Experience profile so we are deleting that contact on same method after sending email. However, log file showing the below error :
WARN Unhandled exception thrown while processing task '0xB18D3ABA71473240B0D4C6B889600324' from task pool 'dispatch_failed_task_pool'. The task has not reached the maximum number of attempts to process a failing task and is postponed.
Exception: System.ArgumentNullException
Message: Value cannot be null.
Parameter name: contact
Source: Sitecore.Kernel
at Sitecore.Diagnostics.Assert.ArgumentNotNull(Object argument, String argumentName)
at Sitecore.EmailCampaign.Cm.Pipelines.UpdateUndeliveredCount.UpdateBounceCount(HandleMessageEventPipelineArgs args, Contact contact)
at (Object , Object )
at Sitecore.Pipelines.CorePipeline.Run(PipelineArgs args)
at Sitecore.Pipelines.DefaultCorePipelineManager.Run(String pipelineName, PipelineArgs args, String pipelineDomain, Boolean failIfNotExists)
at Sitecore.Pipelines.DefaultCorePipelineManager.Run(String pipelineName, PipelineArgs args, String pipelineDomain)
at Sitecore.Modules.EmailCampaign.Core.PipelineHelper.RunPipeline(String pipelineName, PipelineArgs args)
at Sitecore.EmailCampaign.Cm.Tasks.MessageEventBaseTaskProcessor.OnProcess(ShortRunningTask task, CancellationToken cancellationToken)
at Sitecore.ExM.Framework.Distributed.Tasks.Processing.ShortRunning.TaskProcessor.Process(ShortRunningTask task, CancellationToken cancellationToken)
at Sitecore.ExM.Framework.Distributed.Tasks.Processing.ShortRunning.DatabaseTaskAgent.ProcessTask(DatabaseTaskDtoCollectionItem taskDto, CancellationToken cancellationToken)
When we are adding breakpoint in the code there and wait for few second then we are getting email and contact removed code working fine. Only issue here we need to send email as well before deleting that contact.
We are using the below code for sending the email :
var message = new AutomatedMessage();
message.ContactIdentifier =contact;
message.MessageId = messageId;
message.TargetLanguage = Sitecore.Context.Language.Name;
clientApiService.SendAutomatedMessage(message);
For deleting contact details we are using the below code :
var reference = new Sitecore.XConnect.IdentifiedContactReference(source, identifier);
Contact contact = client.Get<Sitecore.XConnect.Contact>(reference, new Sitecore.XConnect.ContactExpandOptions() { });
client.ExecuteRightToBeForgotten(contact);
client.Submit();
Could someone suggest me how can we achieve this functionality?