I came across business requirement where I want to delete item from master & web and also delete respective item from solr indexes. business don't want to publish parent item as there might be change i sibling or parent so I cant trigger any strategy like a onPublishEndAsync , onPublishEndAsyncSingleInstance onPublishEndAsyncPreview here I am trying something like below but it is not working
var ParentItem = item.Parent;
using (new EditContext(item))
{
if (Sitecore.Configuration.Settings.RecycleBinActive)
item.Recycle();
else
item.Delete();
}
if (item == null)
return;
ISearchIndex index = ContentSearchManager.GetIndex((SitecoreIndexableItem)ParentItem );
if (index == null)
return;
index.Refresh(new SitecoreIndexableItem(ParentItem )); or
index.RefreshAsync(new SitecoreIndexableItem(item), IndexingOptions.ForcedIndexing, new System.Threading.CancellationToken());
I am not getting any error in sitecore log or solr log files but index is not deleting item
You can mark your item as unpublishable, publish it (that will remove the item from
web
database and fromweb
index) and then delete it.Here is sample code which unpublished item from all publishing target databases:
Just execute
item.Recycle
orDelete
after.Some time ago I wrote a blog post describing how to add a ribbon button which will "Delete and Unpublish" item with one click. You can find it here:
Automatically unpublish deleted Sitecore item