@@ -3,6 +3,7 @@ import getRelatedList from '@salesforce/apex/TAG_RelatedListController.getRelate
3
3
import { NavigationMixin } from 'lightning/navigation' ;
4
4
import { getRecord } from 'lightning/uiRecordApi' ;
5
5
import { getObjectInfo } from 'lightning/uiObjectInfoApi' ;
6
+ import { getObjectInfos } from 'lightning/uiObjectInfoApi' ;
6
7
import { encodeDefaultFieldValues } from 'lightning/pageReferenceUtils' ;
7
8
8
9
export default class TagRelatedList extends NavigationMixin ( LightningElement ) {
@@ -43,6 +44,31 @@ export default class TagRelatedList extends NavigationMixin(LightningElement) {
43
44
this . getList ( ) ;
44
45
}
45
46
47
+ get relatedObjectNames ( ) {
48
+ if ( ! this . displayedFields ) return [ ] ;
49
+ const fields = this . displayedFields . replace ( / \s / g, '' ) . split ( ',' ) ;
50
+ const related = new Set ( ) ;
51
+ fields . forEach ( field => {
52
+ if ( field . includes ( '.' ) ) {
53
+ let relationship = field . split ( '.' ) [ 0 ] ;
54
+ related . add ( relationship ) ;
55
+ }
56
+ } ) ;
57
+ return Array . from ( related ) ;
58
+ }
59
+
60
+ @wire ( getObjectInfos , { objectApiNames : '$relatedObjectNames' } )
61
+ wiredRelatedObjectInfos ( { data, error } ) {
62
+ if ( data ) {
63
+ this . relatedObjectMetadata = data . results . reduce ( ( acc , item ) => {
64
+ acc [ item . result . apiName ] = item . result . fields ;
65
+ return acc ;
66
+ } , { } ) ;
67
+ } else if ( error ) {
68
+ console . error ( 'Error fetching related object metadata:' , error ) ;
69
+ }
70
+ }
71
+
46
72
@wire ( getObjectInfo , { objectApiName : '$relatedObjectApiName' } )
47
73
objectInfo ;
48
74
@@ -309,18 +335,29 @@ export default class TagRelatedList extends NavigationMixin(LightningElement) {
309
335
if ( ! this . popoverRecordData || ! this . objectInfo . data ) {
310
336
return [ ] ;
311
337
}
338
+
312
339
return this . combinedPopoverFields . map ( fieldApiName => {
313
- // Look up the localized label (if available); if not, fallback to field API name
314
- let fieldLabel = this . objectInfo . data . fields [ fieldApiName ] ?
315
- this . objectInfo . data . fields [ fieldApiName ] . label :
316
- fieldApiName ;
340
+ let fieldLabel ;
341
+
342
+ if ( fieldApiName . includes ( '.' ) ) {
343
+ let [ relationship , childField ] = fieldApiName . split ( '.' ) ;
344
+
345
+ if ( this . relatedObjectMetadata [ relationship ] && this . relatedObjectMetadata [ relationship ] [ childField ] ) {
346
+ fieldLabel = this . relatedObjectMetadata [ relationship ] [ childField ] . label ;
347
+ } else {
348
+ fieldLabel = childField ;
349
+ }
350
+ } else {
351
+ fieldLabel = this . objectInfo . data . fields [ fieldApiName ] ?. label || fieldApiName ;
352
+ }
353
+
317
354
return {
318
- apiName : fieldLabel , // Using the localized label here instead of the API name
355
+ apiName : fieldLabel ,
319
356
value : this . resolve ( fieldApiName , this . popoverRecordData )
320
357
} ;
321
358
} ) ;
322
- }
323
-
359
+ }
360
+
324
361
// Getter for popover style
325
362
get popoverStyle ( ) {
326
363
if ( this . popoverPosition ) {
0 commit comments