Send xAPI from Apex

Send xAPI from Apex

The xAPI Statement class enables the assembly and transmission of complex xAPI statements to your LRS. You can find the class definition here.

Example statement

In this example, we create and transmit an xAPI statement using specific values. In your implementation, you will extract information from your Salesforce data schema. The locale that was specified during setup will be used by the statement fields that require it.

Instantiate an xAPI Statement.

Globebyte.XapiStatement statement = new Globebyte.XapiStatement();

Set the actor’s name and use MBox for user identification. For other user identification cases, you can use setActorOpenId, setActorAccount, and setActorMboxSha1Sum.

statement.xapiActor.setName('xAPI Tester');
statement.xapiActor.setMbox('[email protected]');

Set the verb id and its display name.

statement.xapiVerb.setId('http://adlnet.gov/expapi/verbs/experienced');
statement.xapiVerb.setDisplay('Read the course introduction');

Set the object id and name.

statement.xapiObject.setId('https://globebyte.com/pathway/course/hr/code/234');
statement.xapiObject.setName('HR on-boarding course');

Add a context hierarchy. For more complex context structures, including extensions and statement references, refer to the full class documentation.

statement.xapiContext.setActivityId('https://globebyte.com/pathway/course/hr/code/234');
statement.xapiContext.setActitivtyName('HR on-boarding course');
statement.xapiContext.setActivityType('https://globebyte.com/pathway/course');
statement.xapiContext.addActivity('category');

Finally, validate the statement before sending it synchronously. If you are not concerned about the outcome, you can use sendAsync. sendSync will return a boolean (true/false) to indicate whether the send was successful or not. If it returns false, the send was not successful, in which case an error message will have been written to the apex debug log, you can access the log using these instructions.

Below is an example of a full statement.

Sending outcomes

The class supports reporting or taking action based on assessment submissions or measured admission process outcomes by using methods like setResultCompletion or setResultResponse, as well as handling scores.

Authority and platform

Processing xAPI data for reporting purposes can be intricate. You can utilize setAuthority and setVersion to aid in filtering inbound learning telemetry processing.

Last updated