Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

v0.1.6 - Flow Collection For Assignees #20

Merged
merged 2 commits into from
Nov 14, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
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",
"salesforce-round-robin@0.1.3": "04t6g000008C6lwAAC",
"salesforce-round-robin@0.1.4": "04t6g000008C6sAAAS",
"salesforce-round-robin@0.1.5": "04t6g000008Oa2hAAC"
"salesforce-round-robin@0.1.5": "04t6g000008Oa2hAAC",
"salesforce-round-robin@0.1.6": "04t6g000008Oa7sAAC"
}
}