I currently have a Sitecore form that has only one field, an email field. When submitted it sends an automated email to the email address inputted by the user. In the email body, I have a controller rendering that calls a view. The controller rendering has some logic in code behind that requires the current contact. I should be able get the contact through the use of an identifier as stated in this documentation The Identifier I've used is the Tracker.Current.ContactId, I need to get this contactId in the controller but my biggest hurdle is that the Tracker.Current is NULL when the email is being sent resulting to the logic being skipped.

I expect that I would be able to get the GUID when I called the Tracker.Current.ContactId from the controller. It was stated in an answer as well here that the Tracker.Current should be accessible. How come I am unable to access this?

I'm using Sitecore 9 update 1

  • 1
    The linked answer is in reference to EXM 3.5 and Sitecore 8.2 in which case Tracker.Current is utilized. In Sitecore 9, Tracker is most likely null, and you have to fetch the contact from the Query parameters that are available when the message is rendered and fetch the xConnect contact using the contact identifer information available in the query params. Jul 2 '19 at 17:41

You can fetch the Contact Id information from the query parameters in the request URL for the EXM message when it's being generated.

The available query parameters include:

  • ec_contact_id
  • ec_id
  • ec_recipient
  • ec_subscr
  • ec_message_id

Example Code for fetching Contact from EXM Query String

        using (var client = SitecoreXConnectClientConfiguration.GetClient())
                var contactId = new ContactReference(Guid.Parse(HttpContext.Current.Request.QueryString["ec_contact_id"]));

                var expandOptions = new ContactExpandOptions(

                //Get the Contact
                var contact = client.Get(contactId, expandOptions);

            catch (Exception ex)
                Logger.LogError(ex.Message, ex);
                return false;
  • I tried fetching the query strings as you stated on your answer but all of it returned either null or empty when outputted on my email
    – qwert
    Jul 3 '19 at 5:39
  • You'l need to provide way more info then. Screenshots, code, etc. Jul 3 '19 at 6:29
  • Thank you for responding. I've created a new question about this error in this link sitecore.stackexchange.com/questions/19703/… please check it out when you can
    – qwert
    Jul 3 '19 at 9:24

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.