From 60ad43954327e646b05d9dc36cc1ed505ec73fc7 Mon Sep 17 00:00:00 2001 From: James Simone <16430727+jamessimone@users.noreply.github.com> Date: Mon, 21 Oct 2024 18:09:30 -0400 Subject: [PATCH] Fixes name shadowing issue with child subselects --- force-app/repository/Repository.cls | 6 +++--- force-app/repository/RepositoryTests.cls | 8 +++++--- 2 files changed, 8 insertions(+), 6 deletions(-) diff --git a/force-app/repository/Repository.cls b/force-app/repository/Repository.cls index 3ac8afb..6f0b5ce 100644 --- a/force-app/repository/Repository.cls +++ b/force-app/repository/Repository.cls @@ -99,14 +99,14 @@ public virtual without sharing class Repository implements IRepository { List childFields, List optionalWhereFilters, Map fieldToSortOrder, - Integer limitAmount + Integer limitBy ) { return this.addChildFields( childFieldToken, new List{ new QueryField(childFields) }, optionalWhereFilters, fieldToSortOrder, - limitAmount + limitBy ); } @@ -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 childFieldNames = new Set{ 'Id' }; diff --git a/force-app/repository/RepositoryTests.cls b/force-app/repository/RepositoryTests.cls index 9873e88..7cff9a3 100644 --- a/force-app/repository/RepositoryTests.cls +++ b/force-app/repository/RepositoryTests.cls @@ -135,7 +135,7 @@ private class RepositoryTests { .addChildFields( Contact.AccountId, new List{ Contact.AccountId, Contact.LastName }, - new List{ Query.notEquals(Contact.LastName, nameFilter) }, + new List{ Query.equals(Contact.LastName, nameFilter) }, new Map(), 1 ); @@ -143,11 +143,13 @@ private class RepositoryTests { 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{ con, secondRecord, excluded }; List 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