- 30 Jun 2022
- 5 読む分
- 印刷する
- 闇光
- PDF
Relationships to Other Objects: Data
- 更新日 30 Jun 2022
- 5 読む分
- 印刷する
- 闇光
- PDF
Once the ScreenMeet Widget has been added to the Case UI, make the Case Object and the ScreenMeet Live Sessions Objects related. This will let you quickly list all of the ScreenMeet sessions associated with a case as part of the Case's related Objects.
NOTE: This is an advanced topic, and it is recommended that you have some foundational knowledge on relational databases as well as Apex coding to proceed.
Overview
Whenever a ScreenMeet session is created or updated, data is written to the ScreenMeet Live Session object table via the ScreenMeet API using a combination of an Apex Trigger and a Junction Object (many-to-many relationship) to create the related object list. The Apex Trigger will execute after a new row is inserted into the ScreenMeet Live Session table. This trigger will then insert a row into the Junction Object, creating the relationship record between the Case and ScreenMeet Live Session objects.
NOTE: If you cannot build an Apex Trigger in your production organization, you can achieve the same result using a Flow. The Flow is shown later this page.
Creating the Junction Object
- Sign in as a System Administrator.
- Open Setup.
- Enter "Object Manager" into Quick Find, then open the Object Manager.
- Click on Create in the top-right corner and choose Custom Object.
- Enter the follow parameters for your object:
Field Value Label ScreenMeet Case Session Plural Label ScreenMeet Case Sessions Object Name ScreenMeet_Case_Session Description Junction object between cases and ScreenMeet sessions. Record Name Case Session Data Type Text - (Optional) Check whichever Optional or Classification features are desired for your implementation. These do not have an impact on the core functionality.
- Click on Save.
- This should have created an object called ScreenMeet_Case_Session__c. We will need this API name later in the Apex Trigger code.
Add Master-Detail Fields
Once the object has been created, add the related fields to the Case and ScreenMeet Live Session objects.
- Click on Fields & Relationships from the Detail View of your newly created ScreenMeet Case Session object.
- Click New.
- Choose Master-Detail Relationship from the Data Type choice list, then click Next.
- Choose Case from the Related To dropdown, then click Next.
- Enter Case for the field Name. ScreenMeet recommends setting the Sharing Setting to Read Only, but this is ultimately left as a decision for your organization.
- Click Next.
- Choose the appropriate field level security settings for the various profiles, if applicable, then click Next.
- Choose the Page Layouts to which the field will be added, then click Next.
- Choose the Page Layouts that will be added to the Related List. This can also be performed later. Click Save & New to save and start the process of creating the next field.
- Choose Master-Detail Relationship from the Data Type choice list, then click Next.
- Choose ScreenMeet Live Session from the Related To dropdown, then click Next.
- Enter ScreenMeet Live Session for the Field Label.
- Enter ScreenMeet_Live_Session for the Field Name.
- Choose the Sharing Settings appropriate for your use case.
- Click Next.
- Choose the appropriate field-level security settings for the various profiles, if applicable, then click Next.
- Choose the Page Layouts to which the field will be added, then click Next.
- Choose the Page Layouts where the Related List will be added. This can also be performed later. Click Save.
- The Object should have the following fields:
Adding the Trigger
- Open the Object Manager.
- Find the ScreenMeet Live Session Object (API Name: screenmeet__Live_Session__c) and click on it to select it.
- Click on Triggers.
- Click on New.
- Paste the following source code into your trigger then click Save.
trigger Live_Link_Case_Trigger on screenmeet__Live_Session__c (after insert) {
//only execute on inserts
if (Trigger.isInsert) {
//iterates through all new rows being inserted
for (screenmeet__Live_Session__c newSessionRow: Trigger.new) {
//this if statement ensures that we only insert rows into our junction object
//which belong to case objects. It is possible to integrate ScreenMeet into
//many objects and workflows within your Organization
if (newSessionRow.screenmeet__parentObjectType__c == 'case') {
//create a new junction object record
ScreenMeet_Case_Session__c junction = new ScreenMeet_Case_Session__c (
ScreenMeet_Live_Session__c = newSessionRow.Id, //sets the foreign key field to screenmeet__Live_Session__c
Case__c = newSessionRow.screenmeet__parentObjectId__c, //sets the foreign key field to the Case
Name = newSessionRow.screenmeet__session_type__c + ': ' + newSessionRow.screenmeet__Session_Id__c //give a discriptive name to the Junction object
);
//insert the relationship row
insert junction;
}
}
}
}
Create a Flow Instead of using a Trigger
If you prefer to use a Flow instead of a Trigger to create the data relationship between the Case and ScreenMeet Live Sessions object records, follow the steps below.
Upon completion, your Flow should look like this.
1. In Flow Builder, create a Record-Triggered Flow.
2. Configure the Trigger for when A record is created and After the record is saved.
3. Choose ScreenMeet Live Session as the Object with None for the Condition Requirements.
4. Add a Decision to the Flow using the Label Select Parent Object Type and API Name Select_Parent_Object_Type. For Outcome Details, enter Case for both the Label and Outcome API Name. For Condition Requirements to Execute Outcome, select All Conditions Are Met (AND). For Resource, select the Record and screenmeet__parentObjectType__c. Select Equals for Operator and case for Value.
5. Add Get Records to the Flow. Enter Get Case for the Label and Get_Case for the API Name. For the Object, select Case. Enter Select All Conditions Are Met (AND) for Condition Requirements, Id for Field, Equals for Operator and Record screenmeet__parentObjectId__c for Value. Select Not Sorted for Sort Order, store Only the first record and Automatically store all fields.
6. Add Create Records to the Flow with the Label ScreenMeet Relationship Data and API Name ScreenMeet_Relationship_Data. Select One for How Many Records to Create and Use separate resources, and literal values for How to Set the Record Fields. Select ScreenMeet Case Session as the Object. Under Set Field Values for the ScreenMeet Case Session, select Case__c as the Field and Case from Get_Case > Case Id for the Value. Click Add Field and select ScreenMeet_Live_Session__c as the Field and Record > Record Id for the Value.
7. Click Save and Activate the Flow.
Add Permissions for Junction Object
Next, make sure your Service Account has permission to create the Junction Objects and the ScreenMeet Agent has permission to view them.
- Sign in as a System Administrator and open Setup.
- Search for Permission Set in Quick Find, then open Permission Sets.
- Create a new Permission set and call it "ScreenMeet Service Junction Object" and click Object Settings.
- Open the ScreenMeet Case Session permissions.
- Click Edit.
- Enable Read, Edit, Create, and all Field Permissions.
- Click Save.
- Assign the permission set to the service account. Select from two available options:
- You can directly assign it in this permission set.
- You can use a permission set group with all the required permission sets for the service account and assign that Permission Set Group to the service account.
- Return to the Permission Sets setup.
- Create the ScreenMeet Agent Admin Junction Object permission set and click Object Settings.
- Open the ScreenMeet Case Session permissions.
- Click Edit.
- Enable only the Read permission.
- Click Save.
- Assign permissions to the users. Select from two available options:
- You could use Permission Set Groups with all the required permission sets for the Agent/Admin and assign those to the correct users (recommended).
- Assign directly the permission set directly to the users (this requires assigning multiple permissions sets separately and could cause issues if not assigned/unassigned together).