Skip to content

Commit

Permalink
Fixes name shadowing issue with child subselects
Browse files Browse the repository at this point in the history
  • Loading branch information
jamessimone committed Oct 21, 2024
1 parent e5c9134 commit 60ad439
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 6 deletions.
6 changes: 3 additions & 3 deletions force-app/repository/Repository.cls
Original file line number Diff line number Diff line change
Expand Up @@ -99,14 +99,14 @@ public virtual without sharing class Repository implements IRepository {
List<Schema.SObjectField> childFields,
List<Query> optionalWhereFilters,
Map<String, RepositorySortOrder> fieldToSortOrder,
Integer limitAmount
Integer limitBy
) {
return this.addChildFields(
childFieldToken,
new List<QueryField>{ new QueryField(childFields) },
optionalWhereFilters,
fieldToSortOrder,
limitAmount
limitBy
);
}

Expand All @@ -125,7 +125,7 @@ public virtual without sharing class Repository implements IRepository {
'(SELECT {0} FROM {1}' +
this.addWheres(optionalWhereFilters) +
this.getOrderBys(fieldToSortOrder) +
this.getLimitAmount(limitAmount) +
this.getLimitAmount(limitBy) +
')';

Set<String> childFieldNames = new Set<String>{ 'Id' };
Expand Down
8 changes: 5 additions & 3 deletions force-app/repository/RepositoryTests.cls
Original file line number Diff line number Diff line change
Expand Up @@ -135,19 +135,21 @@ private class RepositoryTests {
.addChildFields(
Contact.AccountId,
new List<Schema.SObjectField>{ Contact.AccountId, Contact.LastName },
new List<Query>{ Query.notEquals(Contact.LastName, nameFilter) },
new List<Query>{ Query.equals(Contact.LastName, nameFilter) },
new Map<String, RepositorySortOrder>(),
1
);

Account acc = new Account(Name = 'Parent');
insert acc;
Contact con = new Contact(AccountId = acc.Id, LastName = nameFilter);
insert con;
Contact secondRecord = new Contact(AccountId = acc.Id, LastName = nameFilter);
Contact excluded = new Contact(AccountId = acc.Id, LastName = 'Excluded');
insert new List<Contact>{ con, secondRecord, excluded };

List<Account> accounts = repo.getAll();
System.assertEquals(1, accounts.size());
System.assertEquals(0, accounts.get(0).Contacts.size());
System.assertEquals(1, accounts.get(0).Contacts.size());
}

@IsTest
Expand Down

0 comments on commit 60ad439

Please sign in to comment.