diff --git a/src/Entity/FlaggingCollection.php b/src/Entity/FlaggingCollection.php
index e6a069c..b1fef42 100644
--- a/src/Entity/FlaggingCollection.php
+++ b/src/Entity/FlaggingCollection.php
@@ -225,18 +225,21 @@ class FlaggingCollection extends RevisionableContentEntityBase implements Flaggi
   public function delete() {
     $flag = $this->getRelatedFlag();
     // Do not delete actions when config is progress of synchronization.
-    if ($flag->isSyncing()) {
-      return;
-    }
+    if ($flag) {
+      if ($flag->isSyncing()) {
+        return;
+      }
 
-    $actions = Action::loadMultiple([
-      'flag_action.' . $flag->id() . '_flag',
-      'flag_action.' . $flag->id() . '_unflag',
-    ]);
+      $actions = Action::loadMultiple([
+        'flag_action.' . $flag->id() . '_flag',
+        'flag_action.' . $flag->id() . '_unflag',
+      ]);
+
+      // Remove the flag/unflag actions for this flag and entity combination.
+      foreach ($actions as $action) {
+        $action->delete();
+      }
 
-    // Remove the flag/unflag actions for this flag and entity combination.
-    foreach ($actions as $action) {
-      $action->delete();
     }
     parent::delete();
   }
@@ -250,8 +253,11 @@ class FlaggingCollection extends RevisionableContentEntityBase implements Flaggi
     // related Flag.
     $flagService = \Drupal::service('flag');
     foreach ($entities as $entity) {
-      $flag = $flagService->getFlagById($entity->getRelatedFlag()->id());
-      $flag->delete();
+      $relatedflag = $entity->getRelatedFlag();
+      if ($relatedflag) {
+        $flag = $flagService->getFlagById($relatedflag->id());
+        $flag->delete();
+      }
     }
     parent::preDelete($storage, $entities);
   }
