Newer Version Available

This content describes an older version of this product. View Latest

Assign Records to Owners Using an Assignment Plan

The AssignRecords() Apex method assigns records to users automatically using rules specified in an assignment plan. For example, suppose that you use a web-to-lead generation form to generate inbound leads in Salesforce. You use the AssignRecords() method to assign those leads to sales reps as soon as the lead records are created, reducing the time for sales reps to contact leads.

Signature

Where,
  • maps is the namespace that's available after you install Salesforce Maps.
  • API is the class that contains the global methods exposed to developers.
  • AssignRecords() is the method.

Sample Code

This code assigns accounts to reps based on an existing assignment plan. The AssignRecords() method returns a List<sObject> containing the records that were assigned to an assignment plan, the plan ID, and the records that weren't assigned to an assignment plan.

The AssignRecords() global method uses the last record cache to assign records. As a best practice, schedule assignment of records frequently in a batch to keep the cache up to date. For more information, see Salesforce Help: Schedule and Run Record Assignments.

When you invoke this global method with a trigger or process builder, use the following sample code as a guide. Not following the sample code can result in an infinite loop when your code runs.

Warning

Example

Invocable Example

Trigger Example

Sample Response

This method returns an Apex Map<String, Object> object that contains the records assigned, the plan ID, and records not assigned. This JSON response illustrates the essential data returned.