Advanced: Apply SuperRoundRobin to any custom object or standard object

Version 6 and up

Last published at: 2024-08-01 08:15:41 UTC

SuperRoundRobin out of the box supports the Lead, Account, Contact, Opportunity, Case, Task and Event objects. However, with a little extra setup we can apply the same automatic assignment capabilities to any Object with a User field (either the OwnerId or a custom user lookup field). So you can automatically assign Custom Objects and other Standard Objects like you can with Leads.

It is recommended, and in most cases required, that you perform these steps on a Sandbox org and then push the changes to your Production org via a Change Set. These instructions assume some familiarity with the creation and use of Sandboxes, Apex and Change Sets. We can provide setup guidance (email support@digitaldoctrine.co) and with access to your Sandbox  we can provide setup services. This whole process should take approximately 10 minutes for someone familiar with this aspect of Salesforce administration.

Configuration Steps for other Standard and Custom Objects. This article is not for Lead, Account, Contact, Opportunity, Case, Task or Event assignment.

Add the following SuperRoundRobin fields to the Custom Object or Standard Object whose records you want assigned by SuperRoundRobin in Setup > Object Manager

  1. Add a Picklist field named 'Use Round Robin' with the following six values (uppercase):

    TRUE
    QUEUED
    FALSE
    ASSIGNED
    REJECTED
    NOMATCH

    Leave everything else at their default settings.
    1. Default the picklist to TRUE (if you plan to use automation to set this value to TRUE, deploy the trigger first and then set it to FALSE)
    2. Click next, and leave the field level security at their default values. Next again, and keep the default selection for page layouts.
  2. Add Long Text field named 'Round Robin Info'. Length: 5000.
    1. Click next, and leave the field level security at their default values. Next again, and keep the default selection for page layouts.
  3. Add Number field named 'SRRIndex'
    1. Click next, and leave the field level security at their default values. Next again, unselect the page layout checkboxes, this field should not be on a layout.

Add a Trigger to your Object

  1. On the Object Manager page for your standard or custom object click the Triggers link on the left.
  2. Press the New button on the main page to create a new trigger.
  3. Copy and paste the trigger code below into the code window. Important: replace 'Custom_Object__c' on the first line with the API name of your object. If your object is named 'Super Widgets' the API name is usually 'Super_Widgets__c'. If it is a standard object like Campaign, the API name will just be 'Campaign'. There should be no single quotes around the object name in the trigger.

trigger assign on Custom_Object__c (before insert, before update, after insert, after update) {
switch on trigger.operationType {
when BEFORE_INSERT,BEFORE_UPDATE {
leadassist.ArgonSRR.runSuperRoundRobin(Trigger.New, trigger.isInsert);
}
when AFTER_INSERT {
leadassist.ArgonSRR.runMatchLogs(Trigger.New, true, null);
}
when AFTER_UPDATE {
leadassist.ArgonSRR.runSLACheck(Trigger.New, Trigger.Old);
}
}
}

Add a Test for your trigger
For any trigger to be deployed to production you must have a test class. The following instructions should be completed after you have created the trigger and you have established that SuperRoundRobin operates as expected on your newly triggered object.

  1. Go to Setup > Apex Classes > click on the 'New' button
  2. Name the class SRRTriggerTest. If you have several triggers that need testing either have a new test class for each one, with distinct names, or if you are comfortable with Apex you can duplicate the relevant sections in the test code below as many times as required for the triggers that need testing.
  3. Copy and paste the test code below into the code window. Each line that is preceded with a "//Config required:" line must be configured with values specific to your trigger and object. These sections are in bold type. Only change the sections of code in bold type.

Note: if your version of SRR is pre Version 9.40, or pre Version 2 for SRR Lite, use this test class code.

//test class for SuperRoundRobin triggers on custom objects (and standard objects beyond the out-of-the-box Lead, Account, Contact, Opportunity and Case)
//if you are required to put customer specific configuration into this test class, there will be a comment starting '//Config required:' in the preceding line telling you what to do

@isTest
private class SRRTriggerTest {
@isTest
static void testSRRTrigger() {

//Config required: objectType is the API Name for the object you created the trigger on. e.g. My_Custom_Object__c or Campaign. This example is for Campaign.
String objectType = 'Campaign';
//Config required: objectAssignmentField: by default OwnerId is the field SRR assigns to. If you are configuring a child object replace OwnerId here with the User Lookup field you are assigning with SRR
String objectAssignmentField = 'OwnerId';

//Config required: objectFieldName: select a field from the object that this test will create a MatchRule with. Easiest is to use a String field like Description
String objectFieldName = 'Description';
//Config required: objectFieldValue: the value in the objectFieldName that will cause a positive match. If you set the objectFieldName to 'Description' then put 'DescriptionValue' here.
String objectFieldValue = 'DescriptionValue';

leadassist__MatchGroup__c mg = leadassist.TestDataFactory.setupTestAndReturnMatchGroup(objectType,objectFieldName,objectFieldValue,objectAssignmentField);
Decimal leadcount_before = mg.leadassist__leadcount__c;

//Config required: this line of Apex code creates a new record of the object you created the trigger on. This test example is for the Campaign object. Remember to include any required fields, and the matching field you set above (Description in this example)
Campaign newRecord = new Campaign(Description='DescriptionValue', Name='Example Campaign', Status='Planned', Use_Round_Robin__c='TRUE');

Test.startTest();
insert newRecord;
Test.stopTest();

Campaign cm = [select Id from Campaign where Id = :newRecord.Id];
update cm;

leadassist__MatchGroup__c mgAfter = [select leadassist__leadcount__c from leadassist__MatchGroup__c where Id = :mg.Id];
Decimal leadcount_after = mgAfter.leadassist__leadcount__c;
System.assert(leadcount_after == leadcount_before+1);
}
}

When you have finished configuring this test class, click Save. If it gives you a 'compile' error, it is likely that you have introduced some kind of syntax error. Look very carefully at the code here and compare it to your code. Each line must have a semi colon at the end. Any opening parenthesis must be matched with a closing parenthesis. Any comment lines (starting //) must be on a single line - do not introduce line breaks into those comment lines. All required fields must be included when you create the new record. That includes any fields required due to validation rules. Any variable values for objectType and objectFieldValue fields must be surrounded in single quotes.

If you get a compile error saying that the method TestDataFactory.setupTestAndReturnMatchGroup is not visible, check and ensure in the Version Settings of the test class that it is pointing to the latest (installed) version of SuperRoundRobin. This error is produced if it is pointing to an older version of SuperRoundRobin.

Once you have checked all the above and it is still complaining, send your test code to support@digitaldoctrine.co and we will look over it.

Once saved, you will see a row of buttons above the code - click the 'Run Test' button. If the trigger and test code has been set up correctly, the test will pass and you will be able to add the trigger and the test class to your Change Set, ready for deployment to production. Read more about Change Sets in the Salesforce Help documentation.


Using Your Custom Object in SuperRoundRobin MatchGroups
When you create a MatchGroup in SuperRoundRobin it will default to assigning to the OwnerId field of the Lead object. Simply change these values by selecting your custom object and the desired assignment field.

That's everything you need to do to enable any object to be processed by SuperRoundRobin. Need help? Contact us via Plauti.com/Contact.