HomeGuidesDeveloper HubRelease Notes
Get supportBook a chat
Developer Hub

FieloELR.ModuleService Class

The FieloELR.ModuleService class includes four methods.

Take Module (takeModule)

static FieloELR.ModuleService.ModuleWrapper FieloELR.ModuleService.takeModule (Id moduleId, Id memberId, Set<String> fieldsModule, Set<String> fieldsQuestion, Set<String> fieldsAnswerOption)

Allows you to get information about a Module tied to a specific Member. It also registers the initial time when the Member started the Module. Module (Module Wrapper class) returns Module Response, Questions and Answer Options.

Parameters

ParameterTypeDescription
moduleIdIdModule ID.
memberIdIdMember ID.
fieldsModuleSet<String>Set of API names to return in the response.
fieldsQuestionSet<String>Set of API names to return in the response. If null, no related records list is returned.
fieldsAnswerOptionSet<String>Set of API names to return in the response. If null, no related records list is returned.

Return Value

TypeDescription
FieloELR.ModuleService.ModuleWrapperA Module Wrapper class. Module Wrapper contains the Module information as follows:
class FieloELR.ModuleService.ModuleWrapper{
	//Module record with the Module information
	FieloELR__Module__c module;
	//Module response record created for the current Member related to the taken Module. It must be sent in 'Submit Module' API.
	FieloELR__ModuleResponse__c moduleResponse;
	//List of Questions with choices to show the quizz.
	List<FieloELR__Question__c> questions;
}
Set<String> fieldsModule = new Set<String>{'Name','FieloELR__Description__c', 'FieloELR__ApprovalGrade__c'};
Set<String> fieldsQuestion = new Set<String>{'FieloELR__QuestionText__c','FieloELR__Type__c'};
Set<String> fieldsAnswerOption = new Set<String>{'FieloELR__AnswerOptionText__c','FieloELR__MatchingText__c'};
//getMemberId must be a custom API to obtain the logged Member ID
FieloPLT__Member__c member = [SELECT Id, FieloPLT__Program__c FROM FieloPLT__Member__c WHERE Id =: MemberService.getMemberId()];
FieloELR__Module__c module = [SELECT Id FROM FieloELR__Module__c LIMIT 1];
FieloELR.ModuleService.ModuleWrapper moduleWrapper = FieloELR.ModuleService.takeModule(module.Id, member.Id, fieldsModule, fieldsQuestion, fieldsAnswerOption);
FieloELR__Module__c moduleView = moduleWrapper.module;
//Record is linked to Member
FieloELR__ModuleResponse__c moduleResponse = moduleWrapper.moduleResponse;
//Includes answer options related lists
List<FieloELR__Question__c> questions = moduleWrapper.questions;

Submit Module Response

static FieloELR__ModuleResponse__c FieloELR.ModuleService.submitModuleResponse (FieloELR__ModuleResponse__c moduleResponse, List<FieloELR.QuestionService.QuestionResponseWrapper> questionWrappers)

Allows Members to submit all Module Reponses whose Question Responses have been previously submitted using the FieloELR.QuestionService Class. As a result, it returns the Module Response.

🚧

Question Responses

The FieloELR.QuestionService Class must be called for each Question.

Parameters

ParameterTypeDescription
moduleResponseFieloELR__ModuleResponse__cModule Response record given when calling Take Module.
questionWrappersList<FieloELR.QuestionService.QuestionResponseWrapper>List of Questions Response Wrapper classes. Questions Response Wrapper contains the information as follows:
class FieloELR.QuestionService.QuestionResponseWrapper{
	//Constructor that will receive the Question and the Module Response ID given by the Take Module API.
	global QuestionResponseWrapper(Id moduleResponseId, Question__c question);
	//Set Answer for short answer Questions
	global void setShortAnswer(String answer);
	//Send the Answer option selected for single choice Questions
	global void setAnswer(AnswerOption__c answerOption);
	//Send the list of Answer options selected for multiple choice Questions
	global void setAnswers(List<AnswerOption__c> answerOptions);
	//Send a map with the mapping between options and chosen Answers
	global void setMatchingAnswers(Map<Id,String> answersMap);
}

Return Value

TypeDescription
FieloELR__ModuleResponse__cA single Module Response record.
///Take Module operation (First Page)
Set<String> fieldsModule = new Set<String>{'Name','FieloELR__Description__c', 'FieloELR__ApprovalGrade__c'};
Set<String> fieldsQuestion = new Set<String>{'FieloELR__QuestionText__c','FieloELR__Type__c'};
Set<String> fieldsAnswerOption = new Set<String>{'FieloELR__AnswerText__c','FieloELR__MatchingOption__c'};
FieloELR__Member__c member = [SELECT Id, FieloPLT__Program__c FROM FieloPLT__Member__c WHERE Id =: MemberService.getMemberId()];
FieloELR__Module__c module = [SELECT Id FROM FieloELR__Module__c LIMIT 1];
FieloELR.ModuleService.ModuleWrapper moduleWrapper = FieloELR.ModuleService.takeModule(module.Id, member.Id, fieldsModule, fieldsQuestion, fieldsAnswerOption);

FieloELR__Module__c module = moduleWrapper.module;
FieloELR__ModuleResponse__c moduleResponse = moduleWrapper.moduleResponse; //Record created for the Member which is sent by means of a parameter in `Submit Module´ method.
List<FieloELR__Question__c> questions = moduleWrapper.questions; //It includes answer options related lists.
//Take Module operation is finished.

List<CourseService.QuestionResponseWrapper> questionWrappers = new List<CourseService.QuestionResponseWrapper>();
for(FieloELR__Question__c question : moduleWrapper.questions){
  FieloELR.QuestionService.QuestionResponseWrapper questionWrapper = new FieloELR.QuestionService.QuestionResponseWrapper(moduleResponse.Id, question){
    if(question.FieloELR__Type__c == 'Short Answer'){
      questionWrapper.setShortAnswer('Selected option');
    }else if(question.FieloELR__Type__c == 'Single Choice' || question.FieloELR__Type__c == 'Statement'){
      questionWrapper.setAnswer(selectedAnswerOption);
    }else if(questionType != 'Multiple Choice' && questionType != 'Matching Options'){
      questionWrapper.setAnswers(selectedAnswerOptions);
    }
}
FieloELR__ModuleResponse__c submittedMResponse = FieloELR.ModuleService.submitModuleResponse (moduleResponse, questionWrappers);
//Submit Module operation is finished.

//Check results
Boolean isApproved = submittedMResponse.FieloELR__IsApproved__c;
Decimal grade = submittedMResponse.FieloELR__Grade__c;

Submit Module Response

static FieloELR__ModuleResponse__c FieloELR.ModuleService.submitModuleResponse (FieloELR__ModuleResponse__c moduleResponse)

Allows Members to submit Question Reponses individually by calling the FieloELR.QuestionService. It returns a single Module Response record.

Parameters

ParameterTypeDescription
moduleResponseFieloELR__ModuleResponse__cModule Response record given when calling Take Course.

Return Value

TypeDescription
FieloELR__ModuleResponse__cA record of Module Response.
//Take Module operation (First Page)
Set<String> fieldsModule = new Set<String>{'Name','FieloELR__Description__c', 'FieloELR__ApprovalGrade__c'};
Set<String> fieldsQuestion = new Set<String>{'FieloELR__QuestionText__c','FieloELR__Type__c'};
Set<String> fieldsAnswerOption = new Set<String>{'FieloELR__AnswerText__c','FieloELR__MatchingOption__c'};
FieloELR__Member__c member = [SELECT Id, FieloPLT__Program__c FROM FieloPLT__Member__c WHERE Id =: MemberService.getMemberId()];
FieloELR__Module__c module = [SELECT Id FROM FieloELR__Module__c LIMIT 1];
FieloELR.ModuleService.ModuleWrapper moduleWrapper = FieloELR.ModuleService.takeModule(module.Id, member.Id, fieldsModule, fieldsQuestion, fieldsAnswerOption);

FieloELR__Module__c module = moduleWrapper.module;
FieloELR__ModuleResponse__c moduleResponse = moduleWrapper.moduleResponse; //Record created for the Member which is sent by means of a parameter in `Submit Module´ method.
List<FieloELR__Question__c> questions = moduleWrapper.questions; //It includes answer options related lists
//Take Module operation is finished.

//Submit questions
for(FieloELR__Question__c question : moduleWrapper.questions){
  FieloELR.QuestionService.QuestionResponseWrapper questionWrapper = new FieloELR.QuestionService.QuestionResponseWrapper(moduleResponse.Id, question);
    if(question.FieloELR__Type__c == 'Short Answer'){
      questionWrapper.setShortAnswer('Selected option');
    }else if(question.FieloELR__Type__c == 'Single Choice' || question.FieloELR__Type__c == 'Statement'){
      questionWrapper.setAnswer(selectedAnswerOption);
    }else if(questionType != 'Multiple Choice' && questionType != 'Matching Options'){
      questionWrapper.setAnswers(selectedAnswerOptions);
    }
    //Submit question
    Boolean isCorrect = FieloELR.QuestionService.submitQuestion(questionWrapper);
}
//Finish Submit Questions
//Submit Module operations
FieloELR__ModuleResponse__c submittedMResponse = FieloELR.ModuleService.submitModuleResponse (moduleResponse);
//Submit Module operation is finished.

//Check results
Boolean isApproved = submittedMResponse.FieloELR__IsApproved__c;
Decimal grade = submittedMResponse.FieloELR__Grade__c;

Obtain Module Response

static FieloELR.ModuleService.ModuleResponseResult FieloELR.ModuleService.getModuleResponse (Id moduleResponseId, Set<String> fieldsModuleResponse, Set<String> fieldsQuestion, Set<String> fieldsAnswerOption)

Allows to obtain Module Response, including both Question Responses and Answers.

Parameters

ParameterTypeDescription
moduleResponseIdIdModule Response ID.
fieldsModuleResponseSet<String>Set of API names to return in the response.
fieldsQuestionSet<String>Set of API names to return in the response. If null, no related records list is returned.
fieldsAnswerOptionSet<String>Set of API names to return in the response. If null, no related records list is returned.

Return Value

TypeDescription
FieloELR.ModuleService.ModuleResponseResultIt returns Module Response Result. Module Response Result contains the information as follows:
class FieloELR.ModuleService.ModuleResponseResult{
	//Module Response with qualification based on the received Module Response ID
	ModuleResponse__c moduleResponse;
	//List of Questions Responses for the given Module Response
	List<FieloELR.QuestionService.QuestionResponseResult> questions;
}

class FieloELR.QuestionService.QuestionResponseResult{
	//Question records
	Question__c question;
	//Number of attempts that the Question was taken
	Integer numberOfAttempts;
	//Question Response with qualification of the question
	QuestionResponse__c questionResponse;
	//List of Answers for the given Question
	List<FieloELR.QuestionService.AnswerWrapper> answerWrappers;
	//Flag that will inform if the Member can repeat the same question
	Boolean canRepeatQuestion;
	//Short description with the information about the corrected answers
	String correctedAnswers;
	//Flag that will inform if the corrected Answers should be shown or not
	Boolean showDetailedAnswers;
}

class FieloELR.QuestionService.AnswerWrapper{
	//Answer option record
	AnswerOption__c answerOption;
	//Status for the option (correct, incorrect, neutral)
	String answerStatus;
}
//View Course Status
Id courseId = 'xxxxxxx';
Set<String> fieldsCourseStatus = new Set<String>{'Name','FieloELR__Progress__c','FieloELR__Course__r.Name'};
Set<String> fieldsModuleResponse = new Set<String>{'Name','FieloELR__Grade__c', 'FieloELR__Module__r.Name'};
FieloELR__Member__c member = [SELECT Id, FieloPLT__Program__c FROM FieloPLT__Member__c WHERE Id =: MemberService.getMemberId()];
FieloELR__CourseStatus__c courseStatus = FieloELR.CourseService.getCourses(fieldsCourseStatus, fieldsModuleResponse,new Set<Id>{courseId},  member.Id, null, null, null)[0];
//Finish Course Status view.

//Get Module Responses detail
Set<String> fieldsModuleResponse = new Set<String>{'Name','FieloELR__Grade__c', 'FieloELR__Module__r.Name'};
Set<String> fieldsQuestion = new Set<String>{'Name','FieloELR__QuestionText__c','FieloELR__Type__c'};
Set<String> fieldsAnswerOption = new Set<String>{'Name','FieloELR__TextValue__c','FieloELR__MatchingOption__c'};

for(FieloELR__ModuleResponse__c mr : courseStatus.FieloELR__ModuleResponses__r){
  	FieloELR.ModuleService.ModuleResponseWrapper mrWrapper = FieloELR.ModuleService.getModuleResponse(mr.Id, fieldsModuleResponse, fieldsQuestion, fieldsAnswerOption);

  	for(FieloELR.ModuleService.QuestionResponseWrapper qrWrapper : mrWrapper.questions){
        FieloELR__Question__c question = qrWrapper.question;
        Integer numberOfAttempts = qrWrapper.numberOfAttempts;
        FieloELR__QuestionResponse__c questionResponse = qrWrapper.questionResponse;
        for(FieloELR.ModuleService.AnswerResponse answerResponseWrapper : qrWrapper.answerWrappers){
						FieloELR__AnswerOption__c answerOption = answerResponseWrapper.answerOption;
          	String answerStatus = answerResponseWrapper.answerStatus;
        }
}