Skip to content

Commit

Permalink
Merge pull request #1572 from alexed1/RevertCollectionCommit
Browse files Browse the repository at this point in the history
  • Loading branch information
alexed1 authored Aug 17, 2024
2 parents 0a311e5 + c0ac868 commit 401970d
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 50 deletions.
4 changes: 4 additions & 0 deletions .forceignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
**/jsconfig.json

**/.eslintrc.json

**/tsconfig.json

**/*.ts
4 changes: 4 additions & 0 deletions flow_action_components/CollectionProcessors/.forceignore
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,7 @@ force-app/main/default/flows/Create_Accounts.flow-meta.xml
/force-app/main/default/profiles/
/force-app/main/default/settings/
/force-app/main/default/appMenus/

**/tsconfig.json

**/*.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,22 +6,14 @@ global with sharing class CountRecordsAndFields {
List<SObject> records = curRequest.inputCollection;
String fieldName = curRequest.fieldName;
String fieldValue = curRequest.fieldValue;

//Create a Results object to hold the return values
Results response = new Results();
try {
for (SObject record : records) {
if (!String.isBlank(fieldName) && !String.isBlank(fieldValue)) {
// Retrieve the field value from the record
Object fieldVal = record.get(fieldName);
if (fieldVal != null) {
// Convert the field value to a string for comparison
// Handle boolean fields by converting them to strings
String fieldValStr = (fieldVal instanceof Boolean) ? String.valueOf(fieldVal) : fieldVal.toString();
// Compare the field value string with the provided field value string
if (fieldValStr == fieldValue) {
response.matchedNumber++;
}
if (record.get(fieldName) == fieldValue) {
response.matchedNumber++;
}
}

Expand All @@ -30,12 +22,12 @@ global with sharing class CountRecordsAndFields {
} catch (Exception ex) {
response.errors = ex.getMessage();
}

//Wrap the Results object in a List container (an extra step added to allow this interface to also support bulkification)

responseWrapper.add(response);
}

return responseWrapper;

}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,44 +13,37 @@ public with sharing class ListActionsTest {
static void makeData() {
Test.startTest();
List<Account> testAccounts = new List<Account>();
List<Contact> testContacts = new List<Contact>(); // Added to create contacts

Boolean doNotCallFlag = true; // Initialize the flag
for (Integer i = 0; i < NUMBER_OF_TEST_RECORDS; i++) {
Account acc = new Account(
Name = TEST_RECORD_NAME + i,
Website = '' + i,
AnnualRevenue = 5000
);
testAccounts.add(acc);

// Create contacts with DoNotCall field set for boolean testing
Contact con = new Contact(
LastName = TEST_CONTACT_NAME + i,
AccountId = acc.Id,
DoNotCall = doNotCallFlag // Set the value based on the flag
testAccounts.add(
new Account(
Name = TEST_RECORD_NAME + i,
Website = '' + i,
AnnualRevenue = 5000
)
);
testContacts.add(con);

// Toggle the flag
doNotCallFlag = !doNotCallFlag;
}

// Insert testAccounts without triggering duplicate rules
Database.DMLOptions dml = new Database.DMLOptions();
dml.DuplicateRuleHeader.AllowSave = true;
Database.insert(testAccounts, dml);
insert testContacts; // Insert the test contacts

List<Contact> testContacts = new List<Contact>();
List<Task> testTasks = new List<Task>();
for (Integer i = 0; i < testAccounts.size(); i++) {
testContacts.add(
new Contact(
LastName = TEST_CONTACT_NAME + i,
AccountId = testAccounts[i].Id
)
);
testTasks.add(
new Task(
Subject = TEST_RECORD_NAME + i,
WhatId = testAccounts[0].Id
)
);
}
insert testContacts;
insert testTasks;
Test.stopTest();
}
Expand Down Expand Up @@ -589,20 +582,6 @@ public with sharing class ListActionsTest {
Assert.areEqual(responseWrapper.size(), 1);
Assert.areEqual(1, responseWrapper[0].matchedNumber);
Assert.areEqual(NUMBER_OF_TEST_RECORDS, responseWrapper[0].totalNumber);

// Clear the requests list for the next test
requests.clear();

// Test counting by boolean field 'DoNotCall'
request.inputCollection = getContacts(NUMBER_OF_TEST_RECORDS);
request.fieldName = 'DoNotCall';
request.fieldValue = 'true';
requests.add(request);

responseWrapper = CountRecordsAndFields.count(requests);
Assert.areEqual(responseWrapper.size(), 1);
Assert.areEqual(3, responseWrapper[0].matchedNumber); // Three records should match (even indices)
Assert.areEqual(NUMBER_OF_TEST_RECORDS, responseWrapper[0].totalNumber);
}

//this is incompatible with recent work done on this class. however, there's a new set of test classes in a separate file, so just going to comment this one out
Expand Down Expand Up @@ -764,10 +743,10 @@ public with sharing class ListActionsTest {

private static List<Contact> getContacts(Integer numberOfRecords) {
return [
SELECT Id, LastName, AccountId, DoNotCall
SELECT Id, LastName, AccountId
FROM Contact
ORDER BY LastName
LIMIT :numberOfRecords
];
}
}
}

0 comments on commit 401970d

Please sign in to comment.