Skip to content

Commit

Permalink
Updated some calls to String.join() to remove extra conversions of Se…
Browse files Browse the repository at this point in the history
…t<String> to List<String> - Summer '23 supports iterating over Set<Object> now

Thanks to @jamessimone for the reminder!
  • Loading branch information
jongpie committed Jun 6, 2023
1 parent 9bf4cf0 commit a918d9b
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ public without sharing virtual class LogManagementDataSelector {
* @return `List<SObject>` containing any records in the specified `SObjectType`
*/
public virtual List<SObject> getAll(Schema.SObjectType sobjectType, Set<String> fieldNames) {
String query = String.format('SELECT {0} FROM {1}', new List<Object>{ String.join(new List<String>(fieldNames), ', '), sobjectType });
String query = String.format('SELECT {0} FROM {1}', new List<Object>{ String.join(fieldNames, ', '), sobjectType });
return Database.query(String.escapeSingleQuotes(query));
}

Expand All @@ -46,7 +46,7 @@ public without sharing virtual class LogManagementDataSelector {
public virtual List<SObject> getById(Schema.SObjectType sobjectType, Set<String> fieldNames, List<Id> recordIds) {
String query = String.format(
'SELECT {0} FROM {1} WHERE Id IN :recordIds',
new List<Object>{ String.join(new List<String>(fieldNames), ', '), sobjectType }
new List<Object>{ String.join(fieldNames, ', '), sobjectType }
);
return Database.query(String.escapeSingleQuotes(query));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ private class LogManagementDataSelector_Tests {
static void it_dynamically_queries_all_records_for_specified_sobject_type_and_fields() {
Schema.SObjectType targetSObjectType = Schema.Organization.SObjectType;
Set<String> targetFieldNames = new Set<String>{ Schema.Organization.Id.getDescribe().getName(), Schema.Organization.Name.getDescribe().getName() };
List<Organization> expectedResults = Database.query('SELECT ' + String.join(new List<String>(targetFieldNames), ', ') + ' FROM ' + targetSObjectType);
List<Organization> expectedResults = Database.query('SELECT ' + String.join(targetFieldNames, ', ') + ' FROM ' + targetSObjectType);

List<SObject> returnedResults = LogManagementDataSelector.getInstance().getAll(targetSObjectType, targetFieldNames);

Expand All @@ -23,7 +23,7 @@ private class LogManagementDataSelector_Tests {
Set<String> targetFieldNames = new Set<String>{ Schema.User.Id.getDescribe().getName(), Schema.User.Name.getDescribe().getName() };
List<Id> targetIds = new List<Id>(new Map<Id, User>([SELECT Id FROM User LIMIT 3]).keySet());
List<User> expectedResults = Database.query(
'SELECT ' + String.join(new List<String>(targetFieldNames), ', ') + ' FROM ' + targetSObjectType + ' WHERE Id IN :targetIds'
'SELECT ' + String.join(targetFieldNames, ', ') + ' FROM ' + targetSObjectType + ' WHERE Id IN :targetIds'
);

List<SObject> returnedResults = LogManagementDataSelector.getInstance().getById(targetSObjectType, targetFieldNames, targetIds);
Expand Down

0 comments on commit a918d9b

Please sign in to comment.