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.
var listManager = Sitecore.Configuration.Factory.CreateObject("contactListManager", true) as ContactListManager;
var list = listManager?.FindById(listId); // list is sometimes null