LearningItemEvaluationHandler Class

Contains methods to customize the evaluation process of a learning item.

Namespace

sfdc_enablement

Usage

Extend this class and implement your custom progress evaluation method. Then link this class to a LearningItemType metadata record by passing the Apex class name to the ApexEvaluationHandler field.

Example

This code updates a user’s progress when they take a custom screen flow exercise in an Enablement program. The code updates the progress by checking the number of screens the user has navigated, calculating the progress percentage, and returning the progress status. See Track a User's Progress in a Custom Exercise from Salesforce Developer Guide: Sales Programs and Partner Tracks with Enablement.

1global class ScreenFlowEvaluationHandler extends sfdc_enablement.LearningItemEvaluationHandler {
2    global override sfdc_enablement.LearningEvaluationResult evaluate(sfdc_enablement.LearningEvaluation learningEvaluation) {
3        sfdc_enablement.LearningEvaluationResult result = new sfdc_enablement.LearningEvaluationResult();
4        Double percentage = 100.0d;
5
6        Map<String, Object> details = learningEvaluation.getDetails();
7
8        String currentScreen = (String) details.get('currentScreen');
9
10        String allScreensString = (String) details.get('allScreens');
11        List<String> allScreens = allScreensString.split(',');
12        
13        String status = (String) details.get('status');
14        if (status == 'FINISHED') {
15            percentage = 100;
16        } else {
17            Integer index = 0;
18            for (Integer i = 0; i < allScreens.size(); i++) {
19                if (allScreens.get(i).equals(currentScreen)) {
20                    index = i + 1;
21                    break;
22                }
23            }
24
25            if (index == allScreens.size()) {
26                percentage = 99.0d;
27            } else {
28                percentage = (Double.valueOf(index) / Double.valueOf(allScreens.size())) * 100.0d;
29            }
30        }
31
32        result.setLearningItemProgress(percentage);
33        
34        if (percentage == 100.0d) {
35            result.setLearningItemProgressStatus(sfdc_enablement.LearningItemProgressStatus.Completed);            
36        } else if (percentage == 0.0d) {
37            result.setLearningItemProgressStatus(sfdc_enablement.LearningItemProgressStatus.NotStarted);            
38        } else {
39            result.setLearningItemProgressStatus(sfdc_enablement.LearningItemProgressStatus.InProgress);
40        }
41        
42        return result;
43    }
44}

LearningItemEvaluationHandler Methods

The following are methods for LearningItemEvaluationHandler.

evaluate(learningEvaluation)

Contains the custom logic for evaluating a learning item.

Signature

public Sfdc_enablement.LearningEvaluationResult evaluate(Sfdc_enablement.LearningEvaluation learningEvaluation)

Parameters

learningEvaluation
Type: Sfdc_enablement.LearningEvaluation
The details of the learning item record to be evaluated.

Return Value

Type: Sfdc_enablement.LearningEvaluationResult

The result of the evaluation, including progress and status details.