Skip to content

Commit

Permalink
[show-all-data] Fix field setup link from show all data (#157)
Browse files Browse the repository at this point in the history
  • Loading branch information
tprouvot authored Sep 12, 2023
1 parent 554d90f commit 62595cf
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 7 deletions.
1 change: 1 addition & 0 deletions CHANGES.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

## General

- "Lightning Field Setup" (from show all data) link did not work for CustomMetadataType and CustomSettings [issue 154](https://github.com/tprouvot/Salesforce-Inspector-reloaded/issues/154) (issue by [Camille Guillory](https://github.com/CamilleGuillory))
- Add missing Date Literals [feature 155](https://github.com/tprouvot/Salesforce-Inspector-reloaded/issues/155)
- Allow navigation to the extension tabs (Object, Users, Shortcuts) using keyboard [feature 135](https://github.com/tprouvot/Salesforce-Inspector-reloaded/issues/135) (feature by [Sarath Addanki](https://github.com/asknet))
- Update query on EntityDefinition to avoid missing objects for large orgs [issue 138](https://github.com/tprouvot/Salesforce-Inspector-reloaded/issues/138) (issue by [AjitRajendran](https://github.com/AjitRajendran))
Expand Down
6 changes: 4 additions & 2 deletions addon/inspect.js
Original file line number Diff line number Diff line change
Expand Up @@ -702,9 +702,10 @@ class FieldRow extends TableRow {
this.fieldActionsOpen = !this.fieldActionsOpen;
if (this.fieldActionsOpen && !this.fieldSetupLinksRequested) {
this.fieldSetupLinksRequested = true;
let isCustomSetting = this.rowList.model.objectData?.customSetting;
this.rowList.model.spinFor(
"getting field setup links for" + this.fieldName,
getFieldSetupLinks(this.rowList.model.sfHost, this.rowList.model.objectName(), this.fieldName)
getFieldSetupLinks(this.rowList.model.sfHost, this.rowList.model.objectName(), this.fieldName, isCustomSetting)
.then(setupLinks => this.fieldSetupLinks = setupLinks)
);
}
Expand Down Expand Up @@ -908,9 +909,10 @@ class ChildRow extends TableRow {
this.childSetupLinksRequested = true;
let sobjectName = (this.childDescribe && this.childDescribe.childSObject) || (this.relatedListInfo && this.relatedListInfo.relatedList.sobject);
let fieldName = (this.childDescribe && this.childDescribe.field) || (this.relatedListInfo && this.relatedListInfo.relatedList.field);
let isCustomSetting = this.rowList.model.objectData?.customSetting;
this.rowList.model.spinFor(
"getting relationship setup links for " + this.childName,
getFieldSetupLinks(this.rowList.model.sfHost, sobjectName, fieldName)
getFieldSetupLinks(this.rowList.model.sfHost, sobjectName, fieldName, isCustomSetting)
.then(setupLinks => this.childSetupLinks = setupLinks)
);
}
Expand Down
13 changes: 8 additions & 5 deletions addon/setup-links.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,29 +12,32 @@ export async function getObjectSetupLinks(sfHost, sobjectName) {
};
}

function getFieldDefinitionSetupLinks(sfHost, fieldName, fieldDefinition) {
function getFieldDefinitionSetupLinks(sfHost, fieldName, fieldDefinition, isCustomSetting, isCustomMetadata) {
let durableId = fieldDefinition.DurableId.split(".");
let entityDurableId = durableId[0];
let fieldDurableId = durableId[durableId.length - 1];
let customType = isCustomMetadata ? "CustomMetadata" : isCustomSetting ? "CustomSettings" : "";
let lightSetupLink = isCustomMetadata ? `https://${sfHost}/lightning/setup/${customType}/page?address=%2F${fieldDurableId}%3Fsetupid%3D${customType}` : `https://${sfHost}/lightning/setup/ObjectManager/${entityDurableId}/FieldsAndRelationships/${fieldDurableId}/view`;
return {
lightningSetupLink: `https://${sfHost}/lightning/setup/ObjectManager/${entityDurableId}/FieldsAndRelationships/${fieldDurableId}/view`,
lightningSetupLink: lightSetupLink,
classicSetupLink: fieldName.includes("__")
? `https://${sfHost}/${fieldDurableId}`
: `https://${sfHost}/p/setup/field/StandardFieldAttributes/d?id=${fieldDurableId}&type=${entityDurableId}`
};
}

export async function getFieldSetupLinks(sfHost, sobjectName, fieldName) {
export async function getFieldSetupLinks(sfHost, sobjectName, fieldName, isCustomSetting) {
let {records: fieldDefinitions} = await sfConn.rest(`/services/data/v${apiVersion}/tooling/query/?q=${encodeURIComponent(`select DurableId from FieldDefinition where EntityDefinition.QualifiedApiName = '${sobjectName}' and QualifiedApiName = '${fieldName}'`)}`);
return getFieldDefinitionSetupLinks(sfHost, fieldName, fieldDefinitions[0]);
let isCmdt = sobjectName.endsWith("__mdt");
return getFieldDefinitionSetupLinks(sfHost, fieldName, fieldDefinitions[0], isCustomSetting, isCmdt);
}

export async function getAllFieldSetupLinks(sfHost, sobjectName) {
let {records: fieldDefinitions} = await sfConn.rest(`/services/data/v${apiVersion}/tooling/query/?q=${encodeURIComponent(`select DurableId, QualifiedApiName from FieldDefinition where EntityDefinition.QualifiedApiName = '${sobjectName}'`)}`);
let fields = new Map();
for (let fieldDefinition of fieldDefinitions) {
let fieldName = fieldDefinition.QualifiedApiName;
fields.set(fieldName, getFieldDefinitionSetupLinks(sfHost, fieldName, fieldDefinition));
fields.set(fieldName, getFieldDefinitionSetupLinks(sfHost, fieldName, fieldDefinition, false, false));
}
return fields;
}

0 comments on commit 62595cf

Please sign in to comment.