Relationships to Other Objects: Data
  • 12 Nov 2020
  • 4 Minutes To Read
  • Print
  • Share
  • Dark
    Light

Relationships to Other Objects: Data

  • Print
  • Share
  • Dark
    Light

Now that we have added the ScreenMeet Widget to the Case UI, lets explore how to make the Case Object and the ScreenMeet Live Sessions Objects related, such that we can easily list all of the ScreenMeet sessions associated with a case as part of the Case's related Objects.

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. We will use 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 our Junction Object, creating the relationship record between our Case and ScreenMeet Live Session objects.

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

Now that the object has been created, we need to add the relationship 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. We recommend setting Read Only for the Sharing Setting, but this is ultimately for you to decide what is right 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 add the field to then click Next
  9. Choose the Page Layouts to add the Related List to. This can also be done later. Click Save & New to create 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 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 add the field to then click Next
  18. Choose the Page Layouts to add the Related List to. This can also be done later. Click Save
  19. Now you should have an Object with the following fields:

Adding the Trigger

  1. Open the Object Manager
  2. Find the ScreenMeet Live Session (API Name: screenmeet__Live_Session__c) Object and click on 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;
            }
        }
    }
}


Add Permissions for Junction Object

Next, we need to make sure that our Service Account has permission to create these Junction Objects, while our ScreenMeet Agent has permission to view them.

  1. While Signed In as a System Administrator 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"
  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, for that you have 2 options
    1. You can directly assign it in this permission set
    2. You could 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 it to the users you can again do this in 2 ways
    1. You could use  Permission Set Groups with all the required permission sets for the Agent/Admin and assign those to the right users (recommended)
    2. Assign directly the permission set to the right users (this causes having to assign multiple permissions sets separately and could cause issues if not assigned/unassigned together)


Next: Configure Page Layouts for related lists

Was This Article Helpful?