Trigger Distribution API

Simon Maskell Updated by Simon Maskell

Trigger Distribution

The DE Apex API includes methods to execute trigger distribution functionality programmatically.

Distribute Objects Inside Trigger

When called from a trigger, will distribute records using the configured trigger distributors. The records will be updated with the assignee but won't be saved, that will be left for the trigger to handle.

It can only be used from a "before update" trigger, and like other trigger distributions, requires Distribution Engine to be running to work.

There are two variations of this method:

Variation 1

If a "Is Trigger Enabled" field is defined, will distribute those records from the trigger where the field is checked, otherwise, will distribute all of the records that are part of the trigger.

global static void n2de.GlobalAPITriggerDistribution.distributeObjectsInsideTrigger()
Example
trigger AccountDistributionTrigger on Account (before update) {
n2de.GlobalAPITriggerDistribution.distributeObjectsInsideTrigger();
}

Variation 2

Will distribute all of the provided records.

global static void n2de.GlobalAPITriggerDistribution.distributeObjectsInsideTrigger(List<SObject> objects)
Example

Distribute any accounts that have their account type updated to "Prospect".

trigger AccountDistributionTrigger on Account (before update) {
List<Account> accountsToDistribute = new List<Account>();
for (Account acct : Trigger.new) {
Account oldAccount = Trigger.oldMap.get(acct.Id);
if (oldAccount != null && acct.Type == 'Prospect' && oldAccount.Type != acct.Type) {
accountsToDistribute.add(acct);
}
}
n2de.GlobalAPITriggerDistribution.distributeObjectsInsideTrigger(accountsToDistribute);
}

Distribute Objects

Will distribute all of the provided records using the configured trigger distributors. The records will be updated with the assignee and saved. Requires Distribution Engine to be running to work.

global static void n2de.GlobalAPITriggerDistribution.distributeObjects(List<SObject> objects)
Example

Distribute accounts that are owned by a given user.

List<Account> accounts = [SELECT Id, Name, OwnerId, n2de__Distribution_count__c FROM Account WHERE Owner.Name = 'A User'];
n2de.GlobalAPITriggerDistribution.distributeObjects(accounts);

A number of fields will need to be included in the query depending on your setup:

  • Id
  • Name
  • OwnerId (or your defined assignment field)
  • n2de__Distribution_count__c (for Account, Case, Contact, Opportunity or Lead)
  • Other fields defined in your team/distributor configuration, like filter fields
This method is also available to use within a Salesforce Flow under the name "DE Distribute Records" in the category "Distribution Engine". An example of using it can be found in the Assign on Action article.

How did we do?

System API

Contact