1

I am trying to access the contents of a list using the ContactListManager, but in certain contexts the FindById(listId) method returns null.

This code is actually used as part of a condition in an Engagement Plan, to check if a contact is on a list. If I trigger the code using the "Execute" button in the Engagement Plan then it finds the list okay. I've even output all contact emails in that list to check that it works.

However, if I let the Engagement Plan do its own thing, then when it runs this condition, it does not find the list and returns null.

Is this permissions or context related? Or something else (Sitecore bug)? I've added the true argument to help debug but there are no exceptions in the logs.

My code:

var listManager = Sitecore.Configuration.Factory.CreateObject("contactListManager", true) as ContactListManager;
var list = listManager?.FindById(listId); // list is sometimes null
1

There is a chance the automation engine is not configured to load the facet.

This topic on automation activities, has a section on: Limit the amount of data that is returned

Check what you have on MarketingAutomation.Loading.ContactFacetsConfigurator

1

The problem was that the listManager required privileges to access the list. I wrapped the method call in SecurityDisabler to successfully return the list:

using (new SecurityDisabler()) {
    var listManager = Sitecore.Configuration.Factory.CreateObject("contactListManager", true) as ContactListManager;
    var list = listManager?.FindById(listId);
}

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.