Strapi lifecycle hooks afterDelete not working after delete from admin panel

I currently have 2 lifecycle hooks - afterCreate and afterDelete sending email after an entry is created / deleted by client. Everything is working fine, afterCreate sends email also when I create entry in admin panel, however, when I delete an entry in admin panel, nothing happens. I am using sendgrid as e-mail provider.

module.exports = {
  async afterDelete(event) {
    const { result } = event;
    const date = new Date(result.date);
    if (date.getTime() >= new Date().getTime()) {
      try {
        await strapi.plugins["email"].services.email.send({
          to: email1,
          from: email2,
          subject: subject,
          text: "Deleted",

Could it be that your if condition never evaluates to true? Try setting a breakpoint or a console log very early in the function to see if it gets called.

I don’t think so, because deleting it from the webpage is sending the email correctly. When I checked the deploy logs on production I found this:

Shouldn’t it be DELETE request?

Oh, so I think I figured it out. I need to set up afterDeleteMany because I was deleting it by clicking the checkbox on the left. Even though it was just one entry.

2 Likes

afterDeleteMany worked for me as well.