11/* global React ReactDOM */
22import { sfConn , apiVersion } from "./inspector.js" ;
3- import { copyToClipboard , downloadCsvFile , getStandardObjectNameField , applyProductionStyling } from "./utils.js" ;
3+ import { copyToClipboard , downloadCsvFile , applyProductionStyling } from "./utils.js" ;
44/* global initButton */
55import { getObjectSetupLinks , getFieldSetupLinks } from "./setup-links.js" ;
66import { PageHeader } from "./components/PageHeader.js" ;
@@ -10,66 +10,6 @@ import AgentforceModal from "./components/AgentforceModal.js";
1010// Constants
1111const GET_FIELD_USAGE_LABEL = "Get field usage" ;
1212
13- /**
14- * Builds a SOQL query to fetch a record with lookup name fields.
15- * Uses STANDARD_OBJECT_NAME_FIELDS to only add relationship fields when the referenced object has a name field.
16- * @param {Object } sobjectDescribe - Object describe from REST API
17- * @param {string } recordId - Record Id to fetch
18- * @returns {{query: string, lookupFieldMap: Array<{fieldName: string, relationshipPath: string, nameField: string}>} }
19- */
20- function buildRecordQueryWithLookupNames ( sobjectDescribe , recordId ) {
21- let selectFields = [ ] ;
22- const lookupFieldMap = [ ] ;
23-
24- for ( const field of sobjectDescribe . fields ) {
25- if ( ! field . name || field . name === "attributes" ) {
26- continue ;
27- }
28- selectFields . push ( field . name ) ;
29-
30- if ( field . type === "reference" && field . relationshipName && field . referenceTo && field . referenceTo . length === 1 ) {
31- const referencedObject = field . referenceTo [ 0 ] ;
32- const nameField = getStandardObjectNameField ( referencedObject ) ;
33- if ( nameField !== null ) {
34- const relationshipField = nameField === "N/A" ? "Name" : nameField ;
35- selectFields . push ( field . relationshipName + "." + relationshipField ) ;
36- lookupFieldMap . push ( { fieldName : field . name , relationshipPath : field . relationshipName , nameField : relationshipField } ) ;
37- }
38- }
39- }
40-
41- const query = "SELECT " + selectFields . join ( ", " ) + " FROM " + sobjectDescribe . name + " WHERE Id = '" + recordId + "'" ;
42- return { query, lookupFieldMap} ;
43- }
44-
45- /**
46- * Flattens a SOQL record result and extracts lookup names into lookupNames map.
47- * @param {Object } record - Single record from SOQL query (records[0])
48- * @param {Array } lookupFieldMap - From buildRecordQueryWithLookupNames
49- * @returns {{flatRecord: Object, lookupNames: Object} }
50- */
51- function flattenSoqlRecordWithLookupNames ( record , lookupFieldMap ) {
52- const flatRecord = { } ;
53- const lookupNames = { } ;
54-
55- for ( const key in record ) {
56- if ( key === "attributes" ) {
57- continue ;
58- }
59- const value = record [ key ] ;
60- if ( value && typeof value === "object" && value . attributes ) {
61- const lookupInfo = lookupFieldMap . find ( l => l . relationshipPath === key ) ;
62- if ( lookupInfo && value [ lookupInfo . nameField ] != null ) {
63- lookupNames [ lookupInfo . fieldName ] = value [ lookupInfo . nameField ] ;
64- }
65- } else {
66- flatRecord [ key ] = value ;
67- }
68- }
69-
70- return { flatRecord, lookupNames} ;
71- }
72-
7313class Model {
7414 constructor ( sfHost ) {
7515 this . reactCallback = null ;
@@ -464,26 +404,19 @@ Structure your response clearly with appropriate headings.`;
464404 }
465405 setRecordData ( recordDataPromise ) {
466406 this . spinFor ( "retrieving record" , recordDataPromise . then ( res => {
467- let recordData = res ;
468- if ( res . recordData && res . lookupNames ) {
469- this . lookupNames = res . lookupNames ;
470- recordData = res . recordData ;
471- } else {
472- this . lookupNames = { } ;
473- }
474- for ( let name in recordData ) {
407+ for ( let name in res ) {
475408 if ( name != "attributes" ) {
476- this . fieldRows . getRow ( name ) . dataTypedValue = recordData [ name ] ;
409+ this . fieldRows . getRow ( name ) . dataTypedValue = res [ name ] ;
477410 }
478411 }
479412 this . fieldRows . resortRows ( ) ;
480- this . recordData = recordData ;
413+ this . recordData = res ;
481414 this . fieldRows . showHideColumn ( true , "value" ) ;
482415 this . spinFor (
483416 "describing layout" ,
484417 this . sobjectDescribePromise . then ( sobjectDescribe => {
485418 if ( sobjectDescribe . urls . layouts ) {
486- return sfConn . rest ( sobjectDescribe . urls . layouts + "/" + ( recordData . RecordTypeId || "012000000000000AAA" ) ) ;
419+ return sfConn . rest ( sobjectDescribe . urls . layouts + "/" + ( res . RecordTypeId || "012000000000000AAA" ) ) ;
487420 }
488421 return undefined ;
489422 } ) . then ( layoutDescribe => {
@@ -539,7 +472,6 @@ Structure your response clearly with appropriate headings.`;
539472 }
540473 this . recordData = null ;
541474 this . layoutInfo = null ;
542- this . lookupNames = { } ;
543475 }
544476 startLoading ( ) {
545477
@@ -563,20 +495,9 @@ Structure your response clearly with appropriate headings.`;
563495 this . childRows . resortRows ( ) ;
564496 } ) ) ;
565497
566- // Fetch record data using SOQL query (includes lookup names when referenced object has a name field)
498+ // Fetch record data using record retrieve call
567499 if ( this . recordId ) {
568- const recordPromise = this . sobjectDescribePromise . then ( sobjectDescribe => {
569- const { query, lookupFieldMap} = buildRecordQueryWithLookupNames ( sobjectDescribe , this . recordId ) ;
570- const queryUrl = "/services/data/v" + apiVersion + "/" + ( this . useToolingApi ? "tooling/" : "" ) + "query/?q=" + encodeURIComponent ( query ) ;
571- return sfConn . rest ( queryUrl ) . then ( res => {
572- if ( ! res . records || res . records . length === 0 ) {
573- throw new Error ( "Record not found" ) ;
574- }
575- const { flatRecord, lookupNames} = flattenSoqlRecordWithLookupNames ( res . records [ 0 ] , lookupFieldMap ) ;
576- return { recordData : flatRecord , lookupNames} ;
577- } ) ;
578- } ) ;
579- this . setRecordData ( recordPromise ) ;
500+ this . setRecordData ( sfConn . rest ( "/services/data/v" + apiVersion + "/" + ( this . useToolingApi ? "tooling/" : "" ) + "sobjects/" + this . sobjectName + "/" + this . recordId ) ) ;
580501 }
581502
582503 // Fetch fields using a Tooling API call, which returns fields not readable by the current user, but fails if the user does not have access to the Tooling API.
@@ -1463,9 +1384,6 @@ class FieldRow extends TableRow {
14631384 }
14641385 return false ;
14651386 }
1466- lookupDisplayValue ( ) {
1467- return this . rowList . model . lookupNames ?. [ this . fieldName ] ?? null ;
1468- }
14691387 idLink ( ) {
14701388 return "https://" + this . rowList . model . sfHost + "/" + this . dataTypedValue ;
14711389 }
@@ -2360,10 +2278,9 @@ class FieldValueCell extends React.Component {
23602278 )
23612279 ) ;
23622280 } else if ( row . isId ( ) ) {
2363- const lookupTitle = row . lookupDisplayValue ( ) ? row . lookupDisplayValue ( ) : null ;
23642281 return h ( "td" , { className : col . className , onDoubleClick : this . onTryEdit } ,
23652282 h ( "div" , { className : "pop-menu-container" } ,
2366- h ( "div" , { className : "sfir-inspect-table-text quick-select" } , h ( "a" , { href : row . idLink ( ) /*used to show visited color*/ , onClick : this . onRecordIdClick , title : lookupTitle } , row . dataStringValue ( ) ) ) ,
2283+ h ( "div" , { className : "sfir-inspect-table-text quick-select" } , h ( "a" , { href : row . idLink ( ) /*used to show visited color*/ , onClick : this . onRecordIdClick } , row . dataStringValue ( ) ) ) ,
23672284 row . recordIdPop == null ? null : h ( "div" , { className : "slds-dropdown slds-dropdown_left slds-dropdown_actions pop-menu" } ,
23682285 h ( "ul" , { className : "slds-dropdown__list" } ,
23692286 row . recordIdPop . map ( link =>
0 commit comments