Advanced: Apply SuperRoundRobin to any custom object or standard object

Version 6 and up

Ed Ralph

Last Update 2 months ago

SuperRoundRobin out of the box supports the Lead, Account, Contact, Opportunity and Case objects.  However, with a little extra setup we can apply the same automatic assignment capabilities to any Object with an OwnerId field (i.e. not on the detail side of a Master-Detail relationship).  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 [email protected]) 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 or Case assignment.

Add the following SuperRoundRobin fields to the Custom Object or Standard Object whose records you want assigned by SuperRoundRobin in Setup > Object Manager
If you are enabling the Event or Task object, the custom fields have to be added to the Activity object and you have to use a Text(255) field for the Round Robin Info field.  A Salesforce Oddity.

  1. Add a Picklist field named 'Use Round Robin' with the following values (uppercase): TRUE, QUEUED, FALSE, ASSIGNED, REJECTED, NOMATCH.  Leave everything else at their default settings.
    1. Default the picklist to TRUE (unless you have other automation that will set this to TRUE, or if your reps will manually set it to TRUE)
    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: 1024.
    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 Custom Object

  1. On the Object Manager page for your 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 custom object.  If your custom 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) {

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);

}

}

}

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.


//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: 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);

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();

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.  Once you have checked all the above and it is still complaining, send your test code to [email protected] 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.


SuperRoundRobin MatchGroups

When you create a MatchGroup in SuperRoundRobin, you have to enter the API name of the object you want that MatchGroup to process records for in the Object Type field.  To find the API Name of a Custom Object, go to Setup > Object Manager and find it in the list...  then look at the API Name column.  A Standard Object will typically have an API Name that is the same as the Label, and a Custom Object will have __c at the end.

SuperRoundRobin MatchRules

The Field lookup in the MatchRule configuration is pre-populated with fields from some standard objects.  You must add the Custom Fields or other Standard Fields for the new object you are just configuring, do this with the Field Wizard found in the Utility Tools tab.  See the instructions in this guide for details.

That's everything you need to do to enable any object to be processed by SuperRoundRobin.  Need help?  Email [email protected]

Was this article helpful?

2 out of 2 liked this article

Still need help? Message Us