Trying to delete a page throws Page does not exist

Issue

When you try to delete a page programmatically, you receive an error similar to the following:

10:09:38 *ERROR* delivery: Unhandled Exception: javax.servlet.ServletException: Page '/content/playground/en/test' does not exist.javax.servlet.ServletException: Page '/content/playground/en/test' does not exist. 10:09:38 at com.day.jasper40.runtime.JspRuntimeLibrary.handlePageException(JspRuntimeLibrary.java:891) 10:09:38 at apps.daytest.templates.test.start$jsp._jspService(start$jsp.java:134) 10:09:38 at com.day.jasper40.runtime.HttpJspBase.service(HttpJspBase.java:107) 10:09:38 at javax.servlet.http.HttpServlet.service(HttpServlet.java:853) 10:09:38 at com.day.cq.jsp.JspHandler.doCallInternal(JspHandler.java:342)

You used code similar to the following:

if(pageToDelete.exists())

{

try

{ pageToDelete.startTransaction();

pageToDelete.delete(false);

pageToDelete.commit();

}catch(Exception e) {

pageToDelete.rollback(); }

}

Solution

Remove the transaction code. For example:

if(pageToDelete.exists()) { try { pageToDelete.delete(false); }catch(Exception e) { log.error(e.getMessage(), e); } }

Additional information

It's not necessary to use any transaction code for deleting a page.