Skip to main content

Notifications

Announcements

No record found.

Microsoft Dynamics CRM (Archived)

Exception Calling InstantiateTemplateRequest From a Plugin

Posted on by 240

Hi,

I am getting a strange error when trying to execute an InstantiateTemplateRequest SDK message inside a plugin.

The call is fairly simple and you expect the Response to contain the e-mail activity created with that template.

InstantiateTemplateRequest instTemplate = new InstantiateTemplateRequest();

instTemplate.TemplateId = templatedId;

instTemplate.ObjectId = relatedtoEntityRef.Id;

instTemplate.ObjectType = relatedtoEntityRef.LogicalName;

InstantiateTemplateResponse instTemplateResponse = (InstantiateTemplateResponse)service.Execute(instTemplate);

When calling the service.Execute() an exception is thrown by CRM.

The root error seems to be:

System.NullReferenceException: Object reference not set to an instance of an object.
   at Microsoft.Crm.ObjectModel.TemplateXmlCreatorContact.GetContactXmlAndAddress()

If I try to manually create an e-mail activity through the front-end, I also get a similar error.

Interestingly, it only seems to occur for certain contacts (as others work ok).

This would point to it being data related but I have no idea what could cause this kind of failure.

Has anyone else ever seen this before?

I can post/provide the server trace logs if needed.

Regards,

Shaun Harvey

*This post is locked for comments

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

December Spotlight Star - Muhammad Affan

Congratulations to a top community star!

Top 10 leaders for November!

Congratulations to our November super stars!

Tips for Writing Effective Suggested Answers

Best practices for providing successful forum answers ✍️

Leaderboard

#1
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 291,280 Super User 2024 Season 2

#2
Martin Dráb Profile Picture

Martin Dráb 230,214 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156

Leaderboard

Featured topics

Product updates

Dynamics 365 release plans