diff --git a/grade/edit/letter/index.php b/grade/edit/letter/index.php
index 393afe4..dedd4bf 100644
--- a/grade/edit/letter/index.php
+++ b/grade/edit/letter/index.php
@@ -141,7 +141,7 @@ if (!$edit) {
         if (!$admin and empty($data->override)) {
             $records = $DB->get_records('grade_letters', array('contextid' => $context->id));
             foreach ($records as $record) {
-                $DB->delete_record('grade_letters', array('id' => $record->id));
+                $DB->delete_records('grade_letters', array('id' => $record->id));
                 // Trigger the letter grade deleted event.
                 $event = \core\event\grade_letter_deleted::create(array(
                     'objectid' => $record->id,
diff --git a/lib/gradelib.php b/lib/gradelib.php
index cb31417..9e37c42 100644
--- a/lib/gradelib.php
+++ b/lib/gradelib.php
@@ -1401,7 +1401,7 @@ function remove_grade_letters($context, $showfeedback) {
 
     $records = $DB->get_records('grade_letters', array('contextid' => $context->id));
     foreach ($records as $record) {
-        $DB->delete_record('grade_letters', array('id' => $record->id));
+        $DB->delete_records('grade_letters', array('id' => $record->id));
         // Trigger the letter grade deleted event.
         $event = \core\event\grade_letter_deleted::create(array(
             'objectid' => $record->id,
@@ -1473,7 +1473,7 @@ function grade_course_category_delete($categoryid, $newparentid, $showfeedback)
     $context = context_coursecat::instance($categoryid);
     $records = $DB->get_records('grade_letters', array('contextid' => $context->id));
     foreach ($records as $record) {
-        $DB->delete_record('grade_letters', array('id' => $record->id));
+        $DB->delete_records('grade_letters', array('id' => $record->id));
         // Trigger the letter grade deleted event.
         $event = \core\event\grade_letter_deleted::create(array(
             'objectid' => $record->id,
diff --git a/lib/tests/coursecatlib_test.php b/lib/tests/coursecatlib_test.php
index 54b1099..752ef43 100644
--- a/lib/tests/coursecatlib_test.php
+++ b/lib/tests/coursecatlib_test.php
@@ -281,6 +281,9 @@ class core_coursecatlib_testcase extends advanced_testcase {
         $course2 = $this->getDataGenerator()->create_course(array('category' => $category4->id));
         $course3 = $this->getDataGenerator()->create_course(array('category' => $category4->id));
         $course4 = $this->getDataGenerator()->create_course(array('category' => $category1->id));
+        // We need to insert grade letter records here to make sure that they are removed
+        $coursecontext = context_coursecat::instance($category2->id);
+        $this->insert_grade_letter_records($coursecontext->id);
 
         // Now we have
         // $category1
@@ -315,12 +318,19 @@ class core_coursecatlib_testcase extends advanced_testcase {
         // structure.
 
         $this->assertNull(coursecat::get($category2->id, IGNORE_MISSING, true));
+        $this->assertEmpty($DB->get_records('grade_letters'));
         $this->assertEquals(array(), $category1->get_children());
         $this->assertEquals(array($category4->id), array_keys($category3->get_children()));
         $this->assertEquals($category4->id, $DB->get_field('course', 'category', array('id' => $course2->id)));
         $this->assertEquals($category4->id, $DB->get_field('course', 'category', array('id' => $course3->id)));
         $this->assertEquals($category3->id, $DB->get_field('course', 'category', array('id' => $course1->id)));
 
+
+        // Again we need to insert grade letter records here to make sure that they are removed.
+        // Ideally we would split this test up into multiples but given my time constraints currently...
+        $coursecontext = context_coursecat::instance($category3->id);
+        $this->insert_grade_letter_records($coursecontext->id);
+
         // Delete category 3 completely.
         $this->assertFalse($category3->can_delete_full()); // No luck!
         // Add necessary capabilities.
@@ -335,6 +345,7 @@ class core_coursecatlib_testcase extends advanced_testcase {
 
         // Note that we also have default 'Miscellaneous' category and default 'site' course.
         $this->assertEquals(1, $DB->get_field_sql('SELECT count(*) FROM {course_categories} WHERE id > ?', array($initialcatid)));
+        $this->assertEmpty($DB->get_records('grade_letters'));
         $this->assertEquals($category1->id, $DB->get_field_sql('SELECT max(id) FROM {course_categories}'));
         $this->assertEquals(1, $DB->get_field_sql('SELECT count(*) FROM {course} WHERE id <> ?', array(SITEID)));
         $this->assertEquals(array('id' => $course4->id, 'category' => $category1->id),
@@ -817,4 +828,31 @@ class core_coursecatlib_testcase extends advanced_testcase {
         }
         return $draftid;
     }
+
+    /**
+     * Inserts grade letter record so that the delete methods can be tested
+     *
+     * @param int $contextid Context ID.
+     */
+    private function insert_grade_letter_records($contextid) {
+        global $DB;
+        $newlettersscale = array(
+            array('contextid' => $contextid, 'lowerboundary' => 90.00000, 'letter' => 'A'),
+            array('contextid' => $contextid, 'lowerboundary' => 85.00000, 'letter' => 'A-'),
+            array('contextid' => $contextid, 'lowerboundary' => 80.00000, 'letter' => 'B+'),
+            array('contextid' => $contextid, 'lowerboundary' => 75.00000, 'letter' => 'B'),
+            array('contextid' => $contextid, 'lowerboundary' => 70.00000, 'letter' => 'B-'),
+            array('contextid' => $contextid, 'lowerboundary' => 65.00000, 'letter' => 'C+'),
+            array('contextid' => $contextid, 'lowerboundary' => 54.00000, 'letter' => 'C'),
+            array('contextid' => $contextid, 'lowerboundary' => 50.00000, 'letter' => 'C-'),
+            array('contextid' => $contextid, 'lowerboundary' => 40.00000, 'letter' => 'D+'),
+            array('contextid' => $contextid, 'lowerboundary' => 25.00000, 'letter' => 'D'),
+            array('contextid' => $contextid, 'lowerboundary' => 0.00000, 'letter' => 'F'),
+        );
+
+        foreach ($newlettersscale as $record) {
+            // There is no API to do this, so we have to manually insert into the database.
+            $DB->insert_record('grade_letters', $record);
+        }
+    }
 }
diff --git a/lib/tests/moodlelib_test.php b/lib/tests/moodlelib_test.php
index 80dc799..430f48d 100644
--- a/lib/tests/moodlelib_test.php
+++ b/lib/tests/moodlelib_test.php
@@ -3324,17 +3324,22 @@ class core_moodlelib_testcase extends advanced_testcase {
      * TODO Add asserts to verify other data related to course is deleted as well.
      */
     public function test_remove_course_contents() {
-
+        global $DB;
         $this->resetAfterTest();
 
         $course = $this->getDataGenerator()->create_course();
         $user = $this->getDataGenerator()->create_user();
+
+        $coursecontext = context_course::instance($course->id);
+        $this->insert_grade_letter_records($coursecontext->id);
+
         $gen = $this->getDataGenerator()->get_plugin_generator('core_notes');
         $note = $gen->create_instance(array('courseid' => $course->id, 'userid' => $user->id));
 
         $this->assertNotEquals(false, note_load($note->id));
         remove_course_contents($course->id, false);
         $this->assertFalse(note_load($note->id));
+        $this->assertEmpty($DB->get_records('grade_letters'));
     }
 
     /**
@@ -3452,6 +3457,7 @@ class core_moodlelib_testcase extends advanced_testcase {
         $count = count_words('one…two ブルース … カンベッル');
         $this->assertEquals(4, $count);
     }
+
     /**
      * Tests the getremoteaddr() function.
      */
@@ -3497,10 +3503,10 @@ class core_moodlelib_testcase extends advanced_testcase {
         $_SERVER['HTTP_X_FORWARDED_FOR'] = $xforwardedfor;
 
     }
-
     /*
      * Test emulation of random_bytes() function.
      */
+
     public function test_random_bytes_emulate() {
         $result = random_bytes_emulate(10);
         $this->assertSame(10, strlen($result));
@@ -3526,7 +3532,6 @@ class core_moodlelib_testcase extends advanced_testcase {
         $this->assertSame('', $result);
         $this->assertDebuggingCalled();
     }
-
     /**
      * Test function for creation of random strings.
      */
@@ -3952,4 +3957,31 @@ class core_moodlelib_testcase extends advanced_testcase {
             ],
         ];
     }
+
+    /**
+     * Inserts grade letter record so that the delete methods can be tested
+     *
+     * @param int $contextid Context ID.
+     */
+    private function insert_grade_letter_records($contextid) {
+        global $DB;
+        $newlettersscale = array(
+            array('contextid' => $contextid, 'lowerboundary' => 90.00000, 'letter' => 'A'),
+            array('contextid' => $contextid, 'lowerboundary' => 85.00000, 'letter' => 'A-'),
+            array('contextid' => $contextid, 'lowerboundary' => 80.00000, 'letter' => 'B+'),
+            array('contextid' => $contextid, 'lowerboundary' => 75.00000, 'letter' => 'B'),
+            array('contextid' => $contextid, 'lowerboundary' => 70.00000, 'letter' => 'B-'),
+            array('contextid' => $contextid, 'lowerboundary' => 65.00000, 'letter' => 'C+'),
+            array('contextid' => $contextid, 'lowerboundary' => 54.00000, 'letter' => 'C'),
+            array('contextid' => $contextid, 'lowerboundary' => 50.00000, 'letter' => 'C-'),
+            array('contextid' => $contextid, 'lowerboundary' => 40.00000, 'letter' => 'D+'),
+            array('contextid' => $contextid, 'lowerboundary' => 25.00000, 'letter' => 'D'),
+            array('contextid' => $contextid, 'lowerboundary' => 0.00000, 'letter' => 'F'),
+        );
+
+        foreach ($newlettersscale as $record) {
+            // There is no API to do this, so we have to manually insert into the database.
+            $DB->insert_record('grade_letters', $record);
+        }
+    }
 }
diff --git a/mod/lesson/locallib.php b/mod/lesson/locallib.php
index 767b580..0d8d407 100644
--- a/mod/lesson/locallib.php
+++ b/mod/lesson/locallib.php
@@ -4360,7 +4360,7 @@ abstract class lesson_page extends lesson_base {
             if (count($answers) > 1) {
                 $answer = array_shift($answers);
                 foreach ($answers as $a) {
-                    $DB->delete_record('lesson_answers', array('id' => $a->id));
+                    $DB->delete_records('lesson_answers', array('id' => $a->id));
                 }
             } else if (count($answers) == 1) {
                 $answer = array_shift($answers);
diff --git a/mod/lesson/tests/locallib_test.php b/mod/lesson/tests/locallib_test.php
index dedbb03..3b391fa 100644
--- a/mod/lesson/tests/locallib_test.php
+++ b/mod/lesson/tests/locallib_test.php
@@ -76,4 +76,10 @@ class mod_lesson_locallib_testcase extends advanced_testcase {
             }
         }
     }
+
+    /**
+     * TODO write tests for the locallib update method
+     * I would have tackled this too but I was a bit pressed for time this week.
+     * I found the same syntax error on the delete_records call.
+     */
 }
