Course Versioning - Approve Course Version
rio_ed.REDU_ApproveCourseVersion_FLOW
Overview
This invocable flow method allows users to approve a draft Course version, promoting it to become the new latest version of the Course.
Flow
This invocable method — "Approve Course Version" — is designed to be used within Salesforce Flow to update a draft Course record to become either a new Active course or the new latest version of a Course.
Process:
This method will do the following:
- Update a Course record:
- Status = [Chosen Status]
- Version = Latest previous version + 1, or 1
- Latest = true
- Optionally update extra fields:
- Taken from the populated fields on the Course Version Record parameter.
- Create a new Course Header, or link to a specified Course Header
Parameters to Be Passed (Flow Inputs):
The method accepts a list of input values. Each input must contain the following fields:
-
Approve As
- (Type: Text, Required)
- Determines the approval behavior. Supported values: newCourse, newVersion.
-
Existing Course Header Id
- (Type: Text)
- Existing Course Header record to associate with the approved Course Version. Required when approveAs = newVersion.
-
Course Version Id
- (Type: Text, Required)
- The Course version record to be approved.
-
Course Version Record
- (Type: Course record)
- A partially populated Course record used to update Course Version fields during the approval process.
-
Course Status
- (Type: Text, Required)
- The status value to assign to the approved Course Version.
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:
-
Approve course version response status
- (Type: Text)
- Execution status e.g., success or fail.
-
Approve 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).
-
Version number
- (Type: Number)
- The approved course version number.
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.
- We recommend setting the status to ‘Active’ for approved Courses.
- If you instead want to reject a draft Course, you should just set the status to “Rejected” directly in the flow, instead of calling this invocable method.
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_ApproveCourseVersion_FLOW.Request> requests
- A list of request objects, each containing the following fields:
-
approveAs
- (Type: String, Required)
- Determines the approval behavior. Supported values: newCourse, newVersion.
-
existingCourseHeaderId
- (Type: Id)
- Existing Course Header record to associate with the approved Course Version. Required when approveAs = newVersion.
-
courseVersionId
- (Type: Id, Required)
- The Course version record to be approved.
-
courseVersionRecord
- (Type: hed__Course__c record)
- A partially populated Course record used to update Course Version fields during the approval process.
-
courseStatus
- (Type: String, Required)
- The status value to assign to the approved Course Version.
-
approveAs
- 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).
-
versionNumber
- (Type: Decimal)
- The approved course version number.
-
status
- A list of response objects, each containing:
Sample Code:
// Example: Approve Course Version as a new version (links to an existing Course Header)
Id courseVersionId = 'XXXXXXXXXXXXXXX'; // Replace with a valid Course Version Id
Id existingCourseHeaderId = 'XXXXXXXXXXXXXXX'; // Replace with a valid Course Header Id
// (Optional) Build a course version record with field overrides applied during approval
hed__Course__c courseVersionRecord = new hed__Course__c();
courseVersionRecord.Name = 'Business Analytics';
courseVersionRecord.hed__Course_ID__c = 'BUS101';
// ...
rio_ed.REDU_ApproveCourseVersion_FLOW.Request req = new rio_ed.REDU_ApproveCourseVersion_FLOW.Request();
req.courseVersionId = courseVersionId;
req.approveAs = 'newVersion';
req.existingCourseHeaderId = existingCourseHeaderId;
req.courseVersionRecord = courseVersionRecord; // Optional: skip this to leave fields unchanged
req.courseStatus = 'Active';
List<rio_ed.REDU_ApproveCourseVersion_FLOW.Request> requestList = new List<rio_ed.REDU_ApproveCourseVersion_FLOW.Request>{ req };
List<rio_ed.REDU_ApproveCourseVersion_FLOW.Response> responseList =
rio_ed.REDU_ApproveCourseVersion_FLOW.approveCourseVersion(requestList);
for (rio_ed.REDU_ApproveCourseVersion_FLOW.Response res : responseList) {
System.debug('Status: ' + res.status);
System.debug('Message: ' + res.message);
System.debug('Approved Course Version Id: ' + res.courseVersionId);
System.debug('Course Header Id: ' + res.courseHeaderId);
System.debug('Version Number: ' + res.versionNumber);
}