I am trying to integrate a custom elastic search implementation.
In order to index products, I created a class inherited from CatalogIndexBuilder so when the indexing job is run, I can call my elastic search client to index the catalog items.
I need the start page of the site and for some reason, ContentReference.StartPage is not set. When I run the site normally, the start page is set correctly but not when the scheduled job is run.
check out thie blog post: https://blog.mathiaskunto.com/2014/05/30/episervers-contentreference-startpage-is-an-empty-reference-when-lacking-binding/#li-comment-26488
See Ted's comment:
You may run into similar problems in scheduled jobs. One way around it is to add a wildcard binding (“*”) for your default site.
That will then be your default site definition (as in SiteDefinition.Current.StartPage or ContentReference.StartPage) when there’s no current site, or outside of web requests.
Thanks for the suggestion. I can give that a try and probably will work until I have one site.
Is there a way to figure out which site the job is running for and get the start page based on that?
Are you creating a multisite with several start pages? Otherwise it will not be a problem.If you are running the scheduled the job in a multisite setup though, I don't think there is a way to see which site the job is running on, as the scheduled job is not running on a web request. A possible solution could be to get the RootPage instead (ContentReference.RootPage), and then do a GetChildren to get all start pages, and the find the correct one.