Skip to content

Commit

Permalink
v0.1.6 - Flow Collection For Assignees (#20)
Browse files Browse the repository at this point in the history
* Fixes #11 with @ssk42

---------

Co-authored-by: @ssk42
  • Loading branch information
jamessimone authored Nov 14, 2023
1 parent 27dbc40 commit 2a2fd70
Show file tree
Hide file tree
Showing 7 changed files with 21 additions and 16 deletions.
8 changes: 4 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,12 @@

## Deployment

<a href="https://login.salesforce.com/packaging/installPackage.apexp?p0=04t6g000008Oa2hAAC">
<a href="https://login.salesforce.com/packaging/installPackage.apexp?p0=04t6g000008Oa7sAAC">
<img alt="Deploy to Salesforce"
src="./media/deploy-package-to-prod.png">
</a>

<a href="https://test.salesforce.com/packaging/installPackage.apexp?p0=04t6g000008Oa2hAAC">
<a href="https://test.salesforce.com/packaging/installPackage.apexp?p0=04t6g000008Oa7sAAC">
<img alt="Deploy to Salesforce Sandbox"
src="./media/deploy-package-to-sandbox.png">
</a>
Expand Down Expand Up @@ -55,11 +55,11 @@ You have quite a few options when it comes to performing round robin assignments
Here are a few ways that you can perform assignments:

- You can re-use the static method `FlowRoundRobinAssigner.assign` by creating synthetic `FlowRoundRobinAssigner.FlowInput` records
- You can call use the bundled `QueryAssigner`:
- You can call use the bundled `RoundRobinCollectionAssigner`:

```java
// in a Trigger / trigger handler class
RoundRobinAssigner.IAssignmentRepo queryRepo = new QueryAssigner(
RoundRobinAssigner.IAssignmentRepo queryRepo = new RoundRobinCollectionAssigner(
'SELECT Id FROM User WHERE Some_Condition__c = true', 'Id'
);
RoundRobinAssigner.Details assignmentDetails = new RoundRobinAssigner.Details();
Expand Down
10 changes: 7 additions & 3 deletions core/classes/FlowRoundRobinAssigner.cls
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,11 @@ global without sharing class FlowRoundRobinAssigner {
}

private void validateInput(FlowInput input) {
if (String.isBlank(input.queryToRetrieveAssignees) && String.isBlank(input.assignmentRepoClassName) && input.collectionOfAssignees.size()==0) {
if (
String.isBlank(input.queryToRetrieveAssignees) &&
String.isBlank(input.assignmentRepoClassName) &&
input.collectionOfAssignees.size() == 0
) {
throw new IllegalArgumentException(
'Query To Retrieve Possible Assignees, API name of class implementing RoundRobinAssigner.IAssignment repo, or a collection of at least one user passed in is required!'
);
Expand Down Expand Up @@ -84,9 +88,9 @@ global without sharing class FlowRoundRobinAssigner {
} else if (String.isNotBlank(input.assignmentRepoClassName)) {
assignmentRepo = (RoundRobinAssigner.IAssignmentRepo) Type.forName(input.assignmentRepoClassName).newInstance();
} else if (input.collectionOfAssignees.size() != 0) {
assignmentRepo = new QueryAssigner(input.collectionOfAssignees);
assignmentRepo = new RoundRobinCollectionAssigner(input.collectionOfAssignees);
} else {
assignmentRepo = new QueryAssigner(input.queryToRetrieveAssignees, input.queryIdField);
assignmentRepo = new RoundRobinCollectionAssigner(input.queryToRetrieveAssignees, input.queryIdField);
}
return assignmentRepo;
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
public without sharing class QueryAssigner implements RoundRobinAssigner.IAssignmentRepo {
public without sharing class RoundRobinCollectionAssigner implements RoundRobinAssigner.IAssignmentRepo {
private static final Map<String, List<SObject>> QUERY_TO_RECORDS = new Map<String, List<SObject>>();
private final List<Id> validAssignmentIds;

public QueryAssigner(String query, String assignmentFieldName) {
public RoundRobinCollectionAssigner(String query, String assignmentFieldName) {
Set<Id> assignmentIds = new Set<Id>();
List<SObject> matchingRecords = QUERY_TO_RECORDS.get(query);
if (matchingRecords == null) {
Expand All @@ -16,10 +16,10 @@ public without sharing class QueryAssigner implements RoundRobinAssigner.IAssign
this.validAssignmentIds = new List<Id>(assignmentIds);
}

public QueryAssigner(List<User> flowCollectionOfAssignees) {
public RoundRobinCollectionAssigner(List<User> flowCollectionOfAssignees) {
Set<Id> assignmentIds = new Set<Id>();
for (User assignee : flowCollectionOfAssignees) {
assignmentIds.add(assignee.Id);
assignmentIds.add(assignee.Id);
}

this.validAssignmentIds = new List<Id>(assignmentIds);
Expand Down
File renamed without changes.
2 changes: 1 addition & 1 deletion integration-tests/triggers/QuickTextTrigger.trigger
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
trigger QuickTextTrigger on QuickText(before insert) {
RoundRobinAssigner.IAssignmentRepo queryRepo = new QueryAssigner(
RoundRobinAssigner.IAssignmentRepo queryRepo = new RoundRobinCollectionAssigner(
'SELECT Id FROM User WHERE IsActive = true AND FirstName = \'' +
UserInfo.getFirstName() +
'\' ORDER BY CreatedDate DESC',
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "salesforce-round-robin",
"version": "0.1.5",
"version": "0.1.6",
"description": "Round robin records in Salesforce (SFDC) using Flow or Apex. Performant, fair, fast assignment with configurable user pools",
"repository": {
"type": "git",
Expand Down
7 changes: 4 additions & 3 deletions sfdx-project.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@
"definitionFile": "config/project-scratch-def.json",
"package": "salesforce-round-robin",
"path": "core",
"versionName": "Fixes truncation issue on Round Robin custom setting",
"versionNumber": "0.1.5.0",
"versionName": "Introduces User collection variable for Flow as an alternative to querying for assignees",
"versionNumber": "0.1.6.0",
"versionDescription": "Invocable & Apex-ready Round Robin Assigner for Salesforce Flow, Process Builder, Apex and more",
"releaseNotesUrl": "https://github.com/jamessimone/salesforce-round-robin/releases/latest"
},
Expand All @@ -21,6 +21,7 @@
"salesforce-round-robin": "0Ho6g000000GnClCAK",
"[email protected]": "04t6g000008C6lwAAC",
"[email protected]": "04t6g000008C6sAAAS",
"[email protected]": "04t6g000008Oa2hAAC"
"[email protected]": "04t6g000008Oa2hAAC",
"[email protected]": "04t6g000008Oa7sAAC"
}
}

0 comments on commit 2a2fd70

Please sign in to comment.