Expand my Community achievements bar.

Guidelines for the Responsible Use of Generative AI in the Experience Cloud Community.

Exception while deleting a page programmatically

Avatar

Level 2

Hi ,

 

I am trying to delete AEM page programmatically using pagemanager.delete() OFTB

 

method but  for some pages I am facing an exception it states - Error while deleting page & other exception was Error while creating a version. Does anyone has any idea when does these 2 exception comes 

Note: page that I want to delete is not having any children 

 

Thanks,

2 Replies

Avatar

Community Advisor

Hi @Nimma05 , Please check below to investigate it.

Try with pageManager.delete(pageManager.getPage(pagePath), true) and see if it works.

For the further investigation.

1- Check if the Page is being used by another process (workflow etc.)

2- If the page has multiple versions or is part of a version history, deleting the current version might not be sufficient. You might need to delete all versions or handle versioning.
3- Double-check that the user or service running the deletion code has the required access rights.

Otherwise, for testing, try deleting the page manually in the AEM. This may provide more detailed error messages or pop-ups that can give more clues about the failure

Avatar

Level 6

Hi @Nimma05 

 

These exceptions suggests that exceptions you’re encountering when using PageManager.delete() in AEM are related to issues with the page’s versioning, permissions ensure that the page is not involved in any active workflows. Workflow references can sometimes prevent page deletion.

 

what you can try to skip versioning while deleting a page like

PageManager pageManager = resourceResolver.adaptTo(PageManager.class);
Page page = pageManager.getPage("/content/my-site/page-to-delete");boolean skipVersioning = true;
pageManager.delete(page, skipVersioning);

also check if the page has a corrupt version history you can remove older versions if needed