Newer Version Available
LearningItemSerializeDeserializer Class
Namespace
Usage
The class contains methods to serialize and deserialize custom exercise content between orgs when an Enablement program that includes a custom exercise is migrated from one org to another through change sets or packaging.
Extend the sfdc_enablement.LearningItemSerializeDeserializer Apex abstract class and add the class name to the ApexSerializerDeserializer field of the LearningItemType metadata record. If you don’t add the class name to the LearningItemType metadata record, the customContent property for the custom exercise is empty in the destination org and no corresponding LearningItem record is created for the exercise’s EnblProgramTaskDefinition record.
The serialize method serializes the custom content of the learning item from the source org. This method is called when you retrieve custom content from the source org.
The deserialize method is called during the deployment of a program. This method takes the serialized custom content, recreates the custom object record in the target org, and returns a new learning item record ID.
Example
The sample code serializes and deserializes the custom content for a given learning item of a custom screen flow exercise in an Enablement program. For this example to work, make sure the screen flow exists in the target org.
1global class ScreenFlowSerializerDeserializer extends Sfdc_enablement.LearningItemSerializeDeserializer {
2 // The serialize method returns the serialized output of the
3 // learning item’s custom content.
4 global override String serialize(String learningItemId) {
5 // Get the screen flow record ID associated with the learning item.
6 LearningItem learningItem = [SELECT ScreenFlow_Field__c from LearningItem where Id =: learningItemId LIMIT 1];
7 String screenFlowRecordId = learningItem.ScreenFlow_Field__c;
8
9 // Get the flow version ID associated with that screen flow.
10 ScreenFlow_Object__c screenFlowRecord = [SELECT FlowVersionId__c from ScreenFlow_Object__c where Id =: screenFlowRecordId LIMIT 1];
11 String flowVersionId = screenFlowRecord.FlowVersionId__c;
12
13 // Query the flow definition associated with that flow version.
14 // Get the information you need to recreate the custom object
15 // record in the destination org.
16 // In this example, we're only getting the API name of the
17 // flow version.
18 FlowDefinitionView flowDefinitionView = [SELECT ApiName from FlowDefinitionView where ActiveVersionId =: flowVersionId LIMIT 1];
19
20 // Return the serialized string.
21 // In this example, we're only returning the API name of the flow
22 // definition in the string.
23 return flowDefinitionView.ApiName;
24 }
25
26 // The deserialize method deserializes the string containing the custom
27 // content. In the method, you recreate the custom object record
28 // for the destination org and populate it with the custom content.
29 // Then insert the record in the destination org and return the new
30 // custom object record ID.
31 global override String deserialize(String serializedOutput) {
32 // Find the flow active version ID of the same screen flow in the
33 // destination org.
34 FlowDefinitionView flowDefinitionView = [SELECT ActiveVersionId from FlowDefinitionView where ApiName =: serializedOutput LIMIT 1];
35 String flowActiveVersionId = flowDefinitionView.ActiveVersionId;
36
37 // Create the screen flow custom object record using the
38 // information you passed to the string in the serialize method.
39 // In this example, we only passed the API name of the screen flow
40 // to the string.
41 ScreenFlow_Object__c screenFlowRecord = new ScreenFlow_Object__c();
42 screenFlowRecord.Name = serializedOutput;
43 screenFlowRecord.FlowVersionId__c = flowActiveVersionId;
44
45 // Insert the custom object record into the destination org.
46 insert screenFlowRecord;
47
48 // Return the new screen flow record ID for the new learning item
49 // in the destination org.
50 return screenFlowRecord.Id;
51 }
52}LearningItemSerializeDeserializer Methods
The following are methods for LearningItemSerializeDeserializer.
deserialize(serializedOutput)
Signature
public String deserialize(String serializedOutput)
Parameters
- serializedOutput
- Type: String
- The serialized information of custom content associated with a learning item The serialize(learningItemId) method returns this information as a string that is less than or equal to 250 characters.
serialize(learningItemId)
Signature
public String serialize(String learningItemId)
Parameters
- learningItemId
- Type: String
- The ID of the learning item associated with the custom content to be serialized.
Return Value
Type: String
The serialized information of the custom content of the specified learning item. The format is a string that’s less than or equal to 250 characters long.