Relationships to Other Objects: Data
  • 30 Jun 2022
  • 5 Minutes to read
  • Dark
    Light
  • PDF

Relationships to Other Objects: Data

  • Dark
    Light
  • PDF

Article Summary

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

  1. Sign in as a System Administrator.
  2. Open Setup.
  3. Enter "Object Manager" into Quick Find, then open the Object Manager.
  4. Click on Create in the top-right corner and choose Custom Object.
  5. Enter the follow parameters for your object:
    FieldValue
    LabelScreenMeet Case Session
    Plural LabelScreenMeet Case Sessions
    Object NameScreenMeet_Case_Session
    DescriptionJunction object between cases and ScreenMeet sessions.
    Record NameCase Session
    Data TypeText
  6. (Optional) Check whichever Optional or Classification features are desired for your implementation. These do not have an impact on the core functionality.
  7. Click on Save.
  8. 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.

  1. Click on Fields & Relationships from the Detail View of your newly created ScreenMeet Case Session object.
  2. Click New.
  3. Choose Master-Detail Relationship from the Data Type choice list, then click Next.
  4. Choose Case from the Related To dropdown, then click Next.
  5. 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.
  6. Click Next.
  7. Choose the appropriate field level security settings for the various profiles, if applicable, then click Next. 
  8. Choose the Page Layouts to which the field will be added, then click Next.
  9. 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.
  10. Choose Master-Detail Relationship from the Data Type choice list, then click Next.
  11. Choose ScreenMeet Live Session from the Related To dropdown, then click Next.
  12. Enter ScreenMeet Live Session for the Field Label.
  13. Enter ScreenMeet_Live_Session for the Field Name.
  14. Choose the Sharing Settings appropriate for your use case.
  15. Click Next.
  16. Choose the appropriate field-level security settings for the various profiles, if applicable, then click Next.
  17. Choose the Page Layouts to which the field will be added, then click Next.
  18. Choose the Page Layouts where the Related List will be added. This can also be performed later. Click Save.
  19. The Object should have the following fields:

Adding the Trigger

  1. Open the Object Manager.
  2. Find the ScreenMeet Live Session Object (API Name: screenmeet__Live_Session__c) and click on it to select it.
  3. Click on Triggers.
  4. Click on New.
  5. 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.


Graphical user interface, text, application, email

Description automatically generated


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.

  1. Sign in as a System Administrator and open Setup.
  2. Search for Permission Set in Quick Find, then open Permission Sets.
  3. Create a new Permission set and call it "ScreenMeet Service Junction Object" and click Object Settings.
  4. Open the ScreenMeet Case Session permissions.
  5. Click Edit.
  6. Enable Read, Edit, Create, and all Field Permissions.
  7. Click Save.
  8. Assign the permission set to the service account. Select from two available options:
    1. You can directly assign it in this permission set.
    2. 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.
  9. Return to the Permission Sets setup.
  10. Create the ScreenMeet Agent Admin Junction Object permission set and click Object Settings.
  11. Open the ScreenMeet Case Session permissions.
  12. Click Edit.
  13. Enable only the  Read permission.
  14. Click Save.
  15. Assign permissions to the users. Select from two available options:
    1. You could use  Permission Set Groups with all the required permission sets for the Agent/Admin and assign those to the correct users (recommended).
    2. 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).


Next: Configure Page Layouts for related lists


Was this article helpful?