Manage Training with REST and Apex APIs
To manage learning module assignments programmatically, you can use REST or Apex APIs with record objects.
| Required Editions |
|---|
| Workforce Engagement is available in Lightning Experience |
| Available in: Enterprise, Performance, and Unlimited Editions |
Person Training records represent learning assignments in Workforce Engagement. Assignments are Trailhead learning modules, which are Learning Content records.
REST API Examples
These REST API examples list, create, update, and delete learning assignments in PersonTraining records.
List all learning assignments
1/services/data/v54.0/query?q=SELECT+Id+from+PersonTrainingCreate a learning assignment
1/services/data/v54.0/sobjects/PersonTraining
2{
3"Name": "Person Training 001",
4"TrainingId": "028af5d6-7e23-3cea-66e5-fd8e3bfe7e9c",
5"TrainingType": "T"
6}Update a learning assignment
In this example, 0hRSG00000000zJ2AQ is the ID of the Person Training record to update.
1/services/data/v54.0/sobjects/PersonTraining/0hRSG00000000zJ2AQ
2{
3"Name": "Person Training Module 003"
4}Delete a learning assignment
In this example, 0hRSG00000000zJ2AQ is the ID of the Person Training record to delete.
1/services/data/v54.0/sobjects/PersonTraining/0hRSG00000000zJ2AQApex API Examples
If you use Apex classes to look up learning modules programmatically, place a limit clause on the SOQL query, for example:
1List<LearningContent> aa = [SELECT ExternalId FROM LearningContent
2WHERE Title LIKE '%Accessibility%' LIMIT 5];These example Apex classes create, search, update, delete, and route learning assignments.
Create a learning assignment
1/* InsertPersonTraining.apex */
2PersonTraining Test001 = new PersonTraining();
3Test001.Name = 'Test001';
4Test001.TrainingId = '028af5d6-7e23-3cea-66e5-fd8e3bfe7e9c';
5Test001.TrainingType = 'T';
6
7insert Test001;Search for a learning assignment
1/* SearchPersonTraining.apex */
2PersonTraining training =
3 [SELECT Name, ID FROM PersonTraining
4 WHERE Name='Test001'
5 LIMIT 1];Update a learning assignment
1/* UpdatePersonTraining.apex */
2PersonTraining training =
3 [SELECT Name, Id FROM PersonTraining
4 WHERE Name='newTest001'
5 LIMIT 1];
6
7// Update the training Name
8training.Name = 'newTest001';
9
10update training;
11
12// Verify that the name was updated
13PersonTraining training02 =
14 [SELECT Name, Id FROM PersonTraining WHERE Id=:training.Id];Delete a learning assignment
1PersonTraining training =
2 [SELECT Name, Id FROM PersonTraining
3 WHERE Name='newTest001'
4 LIMIT 1];
5
6delete training;Route a learning assignment
1/* RoutePersonTraining.apex */
2PendingServiceRouting routing = new PendingServiceRouting();
3routing.CapacityWeight = 1;
4
5// To route correctly, PreferredUserId must be the same as AssigneeId.
6routing.preferredUserId = UserInfo.getUserId(); // Assign to current user for testing.
7routing.isPreferredUserRequired = true;
8routing.routingPriority = 1;
9routing.routingType = 'SkillsBased';
10
11// set service channel ID
12routing.serviceChannelId = '0N9SG0000000CHJ'; // Hard-coded the service channel id
13routing.isReadyForRouting = true;
14
15// set workItemId to be person training ID
16routing.workItemId = '0hRSG000000009h2AA';
17
18insert routing;