---
schema_version: "1"
id: c03354cc7290bbf04bcd1f272a46f77e7c490e0238a6812cc5a6944314a48ffd
title: Create Rubric Assessment Questions with Apex Script
collection: admin
version: current
locale: en-us
portal_url: https://docs.salesforce.com/admin/current/en-us/sfdo/264-0-0/ec_create_rubric_assessment_questions_with_apex_script.md
canonical_url: https://help.salesforce.com/s/articleView?id=sfdo.ec_create_rubric_assessment_questions_with_apex_script.htm&release=264.0.0&type=5
source_site: help.salesforce.com
content_type: documentation
content_hash: a43c4af15dcd4bb61194768f1be2ca60ed66a0e47411c4d56f30a9057846c51a
description: Run an Apex script to create the questions that align with the scoring integration procedure that’s used for rubrics.
products:
  - Education
release: "264"
---
# Create Rubric Assessment Questions with Apex Script

Run an Apex script to create the questions that align with the scoring integration procedure that’s used for rubrics.

### Required Editions

<table class="slds-table slds-table_bordered slds-max-medium-table_stacked slds-m-bottom_small edition"><colgroup><col></colgroup><tbody><tr class=""><td class="slds-cell-wrap" style="vertical-align:top;">Available in: Lightning Experience</td></tr><tr class=""><td class="slds-cell-wrap" style="vertical-align:top;">Available in: <strong>Enterprise</strong>, <strong>Performance</strong>, <strong>Unlimited</strong>, and <strong>Developer</strong> Editions with Education Cloud</td></tr></tbody></table>

<table class="slds-table slds-table_bordered slds-max-medium-table_stacked slds-m-bottom_small permission">
      <colgroup>
        <col>
        <col>
      </colgroup>
      <thead class="slds-text-title_caps ">
        <tr class="">
          <th scope="colgroup" class="slds-cell-wrap" colspan="2" style="text-align:center;vertical-align:top;" id="d65302e70">User Permissions
            Needed</th>
        </tr>
      </thead>
      <tbody>
        <tr class="">
          <td data-label="User Permissions Needed" class="slds-cell-wrap" style="vertical-align:top;" headers="d65302e70 ">To add questions to a rubric using Apex script:</td>

          <td class="slds-cell-wrap" style="vertical-align:top;" headers="d65302e70 ">Education Cloud Full Access</td>

        </tr>
      </tbody>
    </table>

`// Controls whether this script will delete records matching this data on developer name before attempting to insert.   // This should only be enabled if you are ok removing the data already present, if it was previously inserted // Note: It will fail if assessment and/or assessment question responses are present Boolean doDeletes = false;  // Controls whether data should be inserted. Boolean doInserts = true;  // Assessment Question Set Name & Dev Name String aqsDevName = 'XApplication_Review_Questions'; String aqsName = 'Application Review Questions';  // Default Response Options String defaultResponseOpts = 'Incomplete or Unacceptable\nAcceptable\nSatisfactory\nExemplary';  // All Question Defaulted Field Values String questionDataType = 'Radio'; String questionQuestionCategory = :alert_spin:'Admissions'; String questionFormulaResponseType = 'Text'; Boolean isQuestionActive = true; Boolean isQuestionOptionSourceResponseValue = false;  Map<String, String> questionNameByQDevName = new Map<String, String>(); Map<String, String> questionByQDevName = new Map<String, String>(); Map<String, String> responseOptsByQDevName = new Map<String, String>();  // Assessment Question 1 Definition String q1DevName =                         'Application_Review_Criterion_Profile'; questionNameByQDevName.put      (q1DevName, 'Application Review Criterion: Profile'); questionByQDevName.put          (q1DevName, 'Is the Profile section complete?'); responseOptsByQDevName.put      (q1DevName, 'Incomplete\nPartly Complete\nComplete');  // Assessment Question 2 Definition String q2DevName =                         'Application_Review_Criteria_Test_Result'; questionNameByQDevName.put     (q2DevName, 'Application Review Criteria: Test Result'); questionByQDevName.put         (q2DevName, 'Rate the applicant’s test results.'); responseOptsByQDevName.put     (q2DevName, defaultResponseOpts);  // Assessment Question 3 Definition String q3DevName =                         'Application_Review_Criteria_College_History'; questionNameByQDevName.put     (q3DevName, 'Application Review Criteria: College History'); questionByQDevName.put         (q3DevName, 'Rate the applicant’s college history.'); responseOptsByQDevName.put     (q3DevName, defaultResponseOpts);  // Assessment Question 4 Definition String q4DevName =                         'Application_Review_Criteria_Secondary_School'; questionNameByQDevName.put     (q4DevName, 'Application Review Criteria: Secondary School'); questionByQDevName.put         (q4DevName, 'Rate the applicant’s secondary school history.'); responseOptsByQDevName.put     (q4DevName, defaultResponseOpts);  // Assessment Question 5 Definition String q5DevName =                         'Application_Review_Criteria_References'; questionNameByQDevName.put     (q5DevName, 'Application Review Criteria: References'); questionByQDevName.put         (q5DevName, 'Rate the applicant’s references.'); responseOptsByQDevName.put     (q5DevName, defaultResponseOpts);  // Assessment Question 6 Definition String q6DevName =                         'Application_Review_Criteria_Family'; questionNameByQDevName.put     (q6DevName, 'Application Review Criteria: Family'); questionByQDevName.put         (q6DevName, 'Is the Family section complete?'); responseOptsByQDevName.put     (q6DevName, 'Incomplete\nPartly Complete\nComplete');  // Assessment Question 7 Definition String q7DevName =                         'Application_Review_Criteria_Files'; questionNameByQDevName.put     (q7DevName, 'Application Review Criteria: Files'); questionByQDevName.put         (q7DevName, 'Have all required files been provided?'); responseOptsByQDevName.put     (q7DevName, 'Not Provided\nPartly Provided\nFully Provided');  // Delete Assessment Question Set, if enabled if (doDeletes) {     // Delete Assessment Question Assignment records, if any     List<AssessmentQuestionAssignment> aqasForDel = [Select Id from AssessmentQuestionAssignment where AssessmentQuestion.DeveloperName in :questionByQDevName.keyset()];     if (aqasForDel.size() > 0) {         delete aqasForDel;     }          // Delete Assessment Question Set record, if present     List<AssessmentQuestionSet> aqsForDel = [select Id from AssessmentQuestionSet where DeveloperName = :aqsDevName];     if (aqsForDel.size() > 0) {     	delete aqsForDel;     }      // Delete Assessment Questions if present     List<AssessmentQuestion> assessmentQuestionsForDel = [select Id, DeveloperName from AssessmentQuestion where DeveloperName in :questionNameByQDevName.keyset()];     if (assessmentQuestionsForDel.size() > 0) {         delete assessmentQuestionsForDel;     } }  if (doInserts) {     // Define and Insert Assessment Question Set     AssessmentQuestionSet assessmentQuestionSet = new AssessmentQuestionSet(         Name = aqsName,         DeveloperName = aqsDevName     );     insert assessmentQuestionSet;      // Insert Questions     List<AssessmentQuestion> assessmentQuestions = new List<AssessmentQuestion>();      for (String qDevName : questionNameByQDevName.keyset()) {     	assessmentQuestions.add(                 new AssessmentQuestion(                     Name = questionNameByQDevName.get(qDevName),                     DeveloperName = qDevName,                     DataType = questionDataType,                     QuestionCategory = questionQuestionCategory,                     FormulaResponseDataType = questionFormulaResponseType                 )             );     }     insert assessmentQuestions;      // Build Map of Assessment Questions By Question Dev Name     Map<String, AssessmentQuestion> assessmentQuestionsByDevName = new Map<String, AssessmentQuestion>();      for (AssessmentQuestion aq : assessmentQuestions) {         assessmentQuestionsByDevName.put(aq.DeveloperName, aq);     }      // Insert Assessment Question Versions     List<AssessmentQuestionVersion> assessmentQuestionVersions = new List<AssessmentQuestionVersion>();      for (String qDevName : questionNameByQDevName.keyset()) {         assessmentQuestionVersions.add(             new AssessmentQuestionVersion(                 Name = questionNameByQDevName.get(qDevName),                 AssessmentQuestionId = assessmentQuestionsByDevName.get(qDevName).Id,                 ResponseValues= responseOptsByQDevName.get(qDevName),                 QuestionText = questionByQDevName.get(qDevName),                 IsActive = isQuestionActive,                 IsOptionSourceResponseValue = isQuestionOptionSourceResponseValue             )         );     }      insert assessmentQuestionVersions;      // Associate Question with Question Set via Assessment Question Assignment     List<AssessmentQuestionAssignment> assessmentQuestionAssignments = new List<AssessmentQuestionAssignment>();      for (String qDevName : questionNameByQDevName.keyset()) {          assessmentQuestionAssignments.add (             new AssessmentQuestionAssignment(                 assessmentQuestionId = assessmentQuestionsByDevName.get(qDevName).Id,                 assessmentQuestionSetId = assessmentQuestionSet.Id             )         );     }      insert assessmentQuestionAssignments; }`