"doc.replaceText" in google apps script not working
===

I have searched and searched for the answer to this but no luck. 
Am trying to replace text from a doc using doc.replaceText(). (Referring to the same tutorial on sending emails from spreadsheets). Whatever I may try, %, #, or any other special characters, my string does not get replaced. Any help would be appreciated. 

Here's my code snippet: 

    function createHtmlMessage(gradesList) 
    {
      
      var templateDocId = ScriptProperties.getProperty("EmailTemplateDoc");
      var docId = DocsList.getFileById(templateDocId).makeCopy().getId();
      var doc = DocumentApp.openById(docId);
      var body = doc.getActiveSection();
      var html = "";
  
      var keys = {
          STUDENT_NAME: "student",
          GR_ENGLISH: gradesList[0],
          GR_MATHS: gradesList[1],
          GR_SCIENCE: gradesList[2],
          GR_SOCIAL: gradesList[3],
          GR_2NDLANG: gradesList[4],
          GR_3RDLANG: gradesList[5],
          GR_COMPUTERS: gradesList[6],
          REMARKS: "remarks"
      };
  
  
      for ( var k in keys ){
         var source = k;
         var dest = keys[k];
         body.replaceText("%" + k + "%", keys[k]);
      }
      html = getDocAsHtml(docId);
  
      DocsList.getFileById(docId).setTrashed(true);
      return html;
    }

All my 'keys' are present in the document with a preceeding and following "%" sign. 