---
schema_version: "1"
id: 54bb33d3e1471c562bca9f7a5593b8bd8ff4ad44e2d82c9d965dffb5d3cd35c7
title: Manage Training with REST and Apex APIs
collection: developer
version: current
locale: en-us
portal_url: https://docs.salesforce.com/developer/current/en-us/service-cloud/wem_cookbook_dev_guide/guides/wem-manage-training-apis.md
canonical_url: https://developer.salesforce.com/docs/service/wem-cookbook-dev-guide/guide/wem-manage-training-apis.html
source_site: developer.salesforce.com
content_type: documentation
content_hash: e6167ac6d904c8060c9c96c77a961ba9df195db2ade4892f28f676a197e8339d
products:
  - Workforce Engagement Developer Guide
  - Service Cloud Developer Content
---

# 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](https://developer.salesforce.com/docs/atlas.en-us.object_reference.meta/object_reference/sforce_api_objects_persontraining.htm) records represent learning assignments in Workforce Engagement. Assignments are Trailhead learning modules, which are [Learning Content](https://developer.salesforce.com/docs/atlas.en-us.object_reference.meta/object_reference/sforce_api_objects_learningcontent.htm) records.

## REST API Examples

These REST API examples list, create, update, and delete learning assignments in PersonTraining records.

**List all learning assignments**

```nolang
/services/data/v54.0/query?q=SELECT+Id+from+PersonTraining
```

**Create a learning assignment**

```nolang
/services/data/v54.0/sobjects/PersonTraining
{
"Name": "Person Training 001",
"TrainingId": "028af5d6-7e23-3cea-66e5-fd8e3bfe7e9c",  
"TrainingType": "T"
}
```

**Update a learning assignment**

In this example, 0hRSG00000000zJ2AQ is the ID of the Person Training record to update.

```nolang
/services/data/v54.0/sobjects/PersonTraining/0hRSG00000000zJ2AQ
{
"Name": "Person Training Module 003"
}
```

**Delete a learning assignment**

In this example, 0hRSG00000000zJ2AQ is the ID of the Person Training record to delete.

```nolang
/services/data/v54.0/sobjects/PersonTraining/0hRSG00000000zJ2AQ
```

## Apex API Examples

If you use Apex classes to look up learning modules programmatically, place a limit clause on the SOQL query, for example:

```nolang
List<LearningContent> aa = [SELECT ExternalId FROM LearningContent
WHERE Title LIKE '%Accessibility%' LIMIT 5];
```

These example Apex classes create, search, update, delete, and route learning assignments.

**Create a learning assignment**

```nolang
/* InsertPersonTraining.apex */
PersonTraining Test001 = new PersonTraining();
Test001.Name = 'Test001';
Test001.TrainingId = '028af5d6-7e23-3cea-66e5-fd8e3bfe7e9c';
Test001.TrainingType = 'T';

insert Test001;
```

**Search for a learning assignment**

```nolang
/* SearchPersonTraining.apex */
PersonTraining  training = 
        [SELECT Name, ID FROM PersonTraining 
         WHERE Name='Test001'
         LIMIT 1];
```

**Update a learning assignment**

```nolang
/* UpdatePersonTraining.apex */
PersonTraining training = 
        [SELECT Name, Id FROM PersonTraining 
         WHERE Name='newTest001'
         LIMIT 1];

// Update the training Name
training.Name = 'newTest001';

update training;

// Verify that the name was updated
PersonTraining training02 = 
    [SELECT Name, Id FROM PersonTraining WHERE Id=:training.Id];
```

**Delete a learning assignment**

```nolang
PersonTraining training = 
        [SELECT Name, Id FROM PersonTraining 
         WHERE Name='newTest001'
         LIMIT 1];

delete training;
```

**Route a learning assignment**

```nolang
/* RoutePersonTraining.apex */
PendingServiceRouting routing = new PendingServiceRouting();
routing.CapacityWeight = 1;

// To route correctly, PreferredUserId must be the same as AssigneeId.
routing.preferredUserId = UserInfo.getUserId(); // Assign to current user for testing.
routing.isPreferredUserRequired = true;
routing.routingPriority = 1;
routing.routingType = 'SkillsBased';

// set service channel ID
routing.serviceChannelId = '0N9SG0000000CHJ'; // Hard-coded the service channel id
routing.isReadyForRouting = true;

// set workItemId to be person training ID
routing.workItemId = '0hRSG000000009h2AA';

insert routing;
```

