Skip to content

Commit d35ef52

Browse files
authoredMar 18, 2025
Merge branch 'main' into record-form
2 parents f4b46aa + 135a61b commit d35ef52

File tree

52 files changed

+1706
-62
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

52 files changed

+1706
-62
lines changed
 

‎config/project-scratch-def.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@
2929
"securitySettings": {
3030
"sessionSettings": {
3131
"forceRelogin": false,
32-
"lockerServiceNext": false
32+
"lockerServiceNext": true
3333
},
3434
"enableAdminLoginAsAnyUser": true
3535
},
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,97 @@
1+
public with sharing class TAG_RelatedListController {
2+
/**
3+
* @description: Returns a list of records
4+
* @return List<sObject>
5+
**/
6+
@AuraEnabled(cacheable=true)
7+
public static List<sObject> getCRMRelatedList(
8+
String parentId,
9+
String objectApiName,
10+
String relationField,
11+
String parentRelationField,
12+
String parentObjectApiName,
13+
String dateField,
14+
String filterConditions,
15+
String orderConditions
16+
) {
17+
Set<String> parentRelationIds = getParentRelation(parentId, parentRelationField, parentObjectApiName);
18+
if (parentRelationIds.isEmpty()) {
19+
return new List<SObject>();
20+
}
21+
22+
String query = 'SELECT Id' + (String.isBlank(dateField) ? '' : ', ' + dateField);
23+
query += ' FROM ' + objectApiName + ' WHERE ';
24+
query += String.isNotBlank(filterConditions) ? filterConditions.trim() + ' AND ' : '';
25+
// query += relationField + ' IN (SELECT ' + parentRelationField + ' FROM ' + parentObjectApiName + ' WHERE Id = \'' + parentId + '\')';
26+
query += relationField + ' IN :parentRelationIds ';
27+
query += 'ORDER BY ' + (orderConditions != null ? orderConditions : 'ID DESC');
28+
29+
List<sObject> returnList = Database.query(query);
30+
return returnList;
31+
}
32+
33+
@AuraEnabled
34+
public static List<sObject> getRelatedList(
35+
List<String> fieldNames,
36+
String parentId,
37+
String objectApiName,
38+
String relationField,
39+
String parentRelationField,
40+
String parentObjectApiName,
41+
String filterConditions
42+
) {
43+
Set<String> parentRelationIds = getParentRelation(parentId, parentRelationField, parentObjectApiName);
44+
String query = 'SELECT ';
45+
46+
//Appending fields to query string
47+
for (String field : fieldNames) {
48+
query += field + ', ';
49+
}
50+
51+
query = query.removeEndIgnoreCase(', ') + ' FROM ' + objectApiName + ' WHERE ';
52+
query += String.isNotBlank(filterConditions) ? filterConditions.trim() + ' AND ' : '';
53+
// query += relationField + ' IN (SELECT ' + parentRelationField + ' FROM ' + parentObjectApiName + ' WHERE Id = \'' + parentId + '\')';
54+
query += relationField + ' IN :parentRelationIds ORDER BY ID DESC';
55+
56+
List<sObject> returnList = Database.query(query);
57+
return returnList;
58+
}
59+
60+
/**
61+
* @description: Returns a set of Strings to be used in getRelatedList
62+
* @return Set<String>
63+
*/
64+
private static Set<String> getParentRelation(
65+
String parentId,
66+
String parentRelationField,
67+
String parentObjectApiName
68+
) {
69+
Set<String> parentRelationIds = new Set<String>();
70+
String query = 'SELECT ' + parentRelationField + ' FROM ' + parentObjectApiName + ' WHERE Id = :parentId';
71+
72+
String relationId;
73+
for (SObject sObj : Database.query(query)) {
74+
relationId = getParentRelationId(sObj, parentRelationField);
75+
if (relationId != null)
76+
parentrelationIds.add(relationId);
77+
}
78+
79+
return parentRelationIds;
80+
}
81+
82+
/**
83+
* @description: Get the parent relation Id from sObject. Will recursively walk through the field hierarchy
84+
* @return String
85+
*/
86+
private static String getParentRelationId(Sobject obj, String parentRelationField) {
87+
List<String> relationHierarchy = parentRelationField.split('\\.');
88+
String fieldApiName = relationHierarchy.remove(0);
89+
90+
if (relationHierarchy.isEmpty()) {
91+
return (String) obj.get(fieldApiName);
92+
} else {
93+
return getParentRelationId(obj.getSObject(fieldApiName), String.join(relationHierarchy, '.'));
94+
}
95+
96+
}
97+
}

0 commit comments

Comments
 (0)