0

We are having a requirement to capture details and update it to custom facet. Whenever there's an identifier (in my case it is,email address from session) it works as expected. I'm able to see the details captured in xDB and I'm also able to retrieve based on identifier. Using the below code. LoadContactReadOnly accepts both identifier and contact id as valid parameters.

    ContactRepository contactRepo = 
  Sitecore.Configuration.Factory.CreateObject("tracking/contactRepository", true)as ContactRepository;
            if (!string.IsNullOrEmpty(UserContext.Current.EmailAddress))
            {
                contact = contactRepo.LoadContactReadOnly(UserContext.Current.EmailAddress);
            }
            else
            {
                contact = contactRepo.LoadContactReadOnly(Tracker.Current.Session.Contact.ContactId);
            }

But when the user is not authenticated (doesn't have email address in session) identifier is not available. Now if I try to retrieve the contact using context contact id I always get a null contact.

What is the effective way to retrieve contacts based on current contact ID? is it possible to get the contacts without identifier? just based on contact id?

I don't see any errors too. Since we are using Sitecore 8.2, update 7. I will not be able to use xConnect.

0

When website user is anonymous his data is stored in session and appears in xDb only when session is ended.

You can force flush contact with his session in xDb by:

var manager = Factory.CreateObject("tracking/contactManager", true) as ContactManager;
manager.FlushContactToXdb(Tracker.Current.Contact);
manager.SaveAndReleaseContactToXdb(contact);

var ctxManager = Factory.CreateObject("tracking/sessionContextManager", true) as SessionContextManagerBase;
ctxManager.Submit(Tracker.Current.Session);

After that you will be able to load contact from xDb by your code LoadContactReadOnly(Tracker.Current.Session.Contact.ContactId);

| improve this answer | |

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.