Course Versioning - Clone Course Version
rio_ed.REDU_CloneCourseVersion_FLOW
Overview
This invocable flow method allows users to create a new Course version by cloning some or all of the details from a previous Course version.
Flow
This invocable method — "Clone Course Version" — is designed to be used within Salesforce Flow to create a new Course record based on an existing Course record.
Process:
This method can do the following:
- Create a new Course record:
- Status = Draft
- Version = null
- All other fields are either:
- All fields are cloned directly from the provided last course version OR
- Taken from the populated fields on the New Course Version Record parameter.
- Optionally create a new Course Header, or link to the same Course Header as the last course version
- Optionally clone child records from the last course version:
- Course Requirements
- Grade Criteria
- Qualified Faculty
- Course Attribute
- Course Learning Outcomes
- Learning Outcome Mappings
Parameters to Be Passed (Flow Inputs):
The method accepts a list of input values. Each input must contain the following fields:
-
Last Course Version Id
- (Type: Text)
- The source Course version record to clone from. Required when cloning an existing course/version.
-
New Course Version Record
- (Type: Course record)
- A partially populated Course record used as the target values for the new cloned Course Version.
-
Clone As
- (Type: Text, Required)
- Determines the cloning behavior. Supported values: newCourse, newVersion.
-
Create or Link Header
- (Type: Boolean)
- Determines whether a Course Header should be created or linked during the cloning process.
-
Clone Child Records
- (Type: Boolean)
- Determines whether related child records should also be cloned.
Each set of these inputs will be processed together. Multiple sets can be passed in one Flow execution.
Response Returned (Flow Outputs):
For each input set, the method will return a corresponding output with the following fields:
-
Clone course version response status
- (Type: Text)
- Execution status e.g., success or fail.
-
Clone course version response message
- (Type: Text)
- A message providing additional information, such as error details if the process failed.
-
Course version id
- (Type: Text)
- The id of the newly created course version record.
-
Course header id
- (Type: Text)
- The id of the newly created course header or existing course id (if one exists).
Usage Tips:
- This method can be used in any kind of flow ( Screen flow, Record-triggered flow, Schedule-Triggered Flow, …)
- If a request fails, the message field will provide a cleaned-up error message for easier troubleshooting.
Flow
For a custom Apex class, we could use the same method exposed from the Flow Invocable Method.
Parameters to Pass:
-
List<rio_ed.REDU_CloneCourseversion_FLOW.Request> requests
- A list of request objects, each containing the following fields:
-
lastCourseVersionId
- (Type: Id)
- The source Course version record to clone from. Required when cloning an existing course/version.
-
newCourseVersionRecord
- (Type: hed__Course__c record)
- A partially populated Course record used as the target values for the new cloned Course Version.
-
cloneAs
- (Type: String, Required)
- Determines the cloning behavior. Supported values: newCourse, newVersion.
-
createOrLinkHeader
- (Type: Boolean)
- Determines whether a Course Header should be created or linked during the cloning process.
-
cloneChildRecords
- (Type: Boolean)
- Determines whether related child records should also be cloned.
-
lastCourseVersionId
- A list of request objects, each containing the following fields:
Return Type:
-
List<rio_ed.REDU_CloneCourseVersion.Response>
- A list of response objects, each containing:
-
status
- (Type: Text)
- Execution status e.g., success or fail.
-
message
- (Type: Text)
- A message providing additional information, such as error details if the process failed.
-
courseVersionId
- (Type: Text)
- The id of the newly created course version record.
-
courseHeaderId
- (Type: Text)
- The id of the newly created course header or existing course id (if one exists).
-
status
- A list of response objects, each containing:
Sample Code:
// Example: Clone Course Version as a new version
Id lastCourseVersionId = 'XXXXXXXXXXXXXXX'; // Replace with a valid Course Id
// (Optional) Build the new course version record with overrides
hed__Course__c newCourseVersionRecord = new hed__Course__c();
newCourseVersionRecord.Name = 'Business Analytics';
newCourseVersionRecord.hed__Account__c = 'XXXXXXXXXXXXXXX'; // Replace with a valid University Department Id
// ...
// Build request
rio_ed.REDU_CloneCourseVersion_FLOW.Request req = new rio_ed.REDU_CloneCourseVersion_FLOW.Request();
req.lastCourseVersionId = lastCourseVersionId;
req.newCourseVersionRecord = newCourseVersionRecord; // Optional: skip this to clone all fields from the original Course
req.cloneAs = 'newVersion';
req.createOrLinkHeader = true;
req.cloneChild = false;
List<rio_ed.REDU_CloneCourseVersion_FLOW.Request> requestList = new List<rio_ed.REDU_CloneCourseVersion_FLOW.Request>{ req };
// Call the invocable method
List<rio_ed.REDU_CloneCourseVersion_FLOW.Response> responseList =
rio_ed.REDU_CloneCourseVersion_FLOW.cloneCourseVersion(requestList);
// Process responses
for (rio_ed.REDU_CloneCourseVersion_FLOW.Response res : responseList) {
System.debug('Status: ' + res.status);
System.debug('Message: ' + res.message);
System.debug('New Course Version Id: ' + res.courseVersionId);
System.debug('Course Header Id: ' + res.courseHeaderId);
}