Skip to content

Commit

Permalink
Fixes issue with parent field chain for QueryField
Browse files Browse the repository at this point in the history
  • Loading branch information
jamessimone committed Oct 22, 2024
1 parent 60ad439 commit 769370b
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 1 deletion.
2 changes: 1 addition & 1 deletion force-app/repository/QueryField.cls
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ public without sharing virtual class QueryField {
public QueryField(List<Schema.SObjectField> parentFieldChain, List<Schema.SObjectField> parentFields) {
String base = '';
while (parentFieldChain.isEmpty() == false) {
base = parentFieldChain.remove(0).getDescribe().getRelationshipName() + '.';
base += parentFieldChain.remove(0).getDescribe().getRelationshipName() + '.';
}
List<String> fields = new List<String>();
for (Schema.SObjectField field : parentFields) {
Expand Down
19 changes: 19 additions & 0 deletions force-app/repository/QueryFieldTests.cls
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
@IsTest
private class QueryFieldTests {
@IsTest
static void parentFieldChainsConcatenatedProperly() {
QueryField queryField = new QueryField(
new List<Schema.SObjectField>{ Contact.AccountId, Account.OwnerId },
new List<Schema.SObjectField>{ User.Email }
);

Assert.areEqual('Account.Owner.Email', queryField.toString());
}

@IsTest
static void concatenatesFieldsProperly() {
QueryField queryField = new QueryField(new List<Schema.SObjectField>{ Contact.AccountId, Contact.LastName });

Assert.areEqual('AccountId,LastName', queryField.toString());
}
}
5 changes: 5 additions & 0 deletions force-app/repository/QueryFieldTests.cls-meta.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
<?xml version="1.0" encoding="UTF-8"?>
<ApexClass xmlns="http://soap.sforce.com/2006/04/metadata">
<apiVersion>62.0</apiVersion>
<status>Active</status>
</ApexClass>

0 comments on commit 769370b

Please sign in to comment.