I am working on Sitecore 10.2 and trying to update facets in xDB. The below function is working fine on local but it is not working on VM. xDB is enabled on Sitecore instance.
public bool SaveContactData(string firstName, string lastName, string identifierSource, string email, string phoneNumber, string language, string userAgent)
{
try
{
var contactReference = GetIdentifiedContactReference(identifierSource, email);
using (var client = SitecoreXConnectClientConfiguration.GetClient())
{
var contact = client.Get(contactReference, new ContactExpandOptions(CollectionModel.FacetKeys.PersonalInformation, CollectionModel.FacetKeys.EmailAddressList, PhoneNumberList.DefaultFacetKey));
//CONTACT IS COMING NULL
}
return true;
}
catch (Exception ex)
{
Log.Error("Error saving data to profile", ex, this);
return false;
}
}
private IdentifiedContactReference GetIdentifiedContactReference(string identifierSource, string identifier)
{
if (Tracker.Enabled && !Tracker.Current.IsActive)
{
Tracker.StartTracking();
}
if (Tracker.Current?.Contact == null)
{
Log.Warn("Tracker.Current?.Contact == null", this);
return null;
}
if (Tracker.Current.Contact.IsNew)
{
Tracker.Current.Contact.ContactSaveMode = ContactSaveMode.AlwaysSave;
_contactManager.SaveContactToCollectionDb(Tracker.Current.Contact);
IdentifyContact(identifierSource, identifier);
return new IdentifiedContactReference(identifierSource, identifier);
}
var id = Tracker.Current.Contact.Identifiers.FirstOrDefault();
return Tracker.Current.Contact.IsNew || Tracker.Current.Contact.Identifiers.Count == 0
? new IdentifiedContactReference(identifierSource, identifier)
: new IdentifiedContactReference(id?.Source, id?.Identifier);
}