Skip to content

Commit

Permalink
Automatically request SObject type when data export from an SObject r…
Browse files Browse the repository at this point in the history
…ecord (#45)
  • Loading branch information
dufoli committed Oct 19, 2023
1 parent 172cee2 commit 25bfbdc
Show file tree
Hide file tree
Showing 4 changed files with 56 additions and 18 deletions.
1 change: 1 addition & 0 deletions CHANGES.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
- Update pop-up release note link to github pages
- Detect SObject on listview page [feature 121](https://github.com/tprouvot/Salesforce-Inspector-reloaded/issues/121) (idea by [Mehdi Cherfaoui](https://github.com/mehdisfdc))
- Automate test setup manual step of contact to multiple accounts [Aidan Majewski](https://github.com/aimaj)
- Automatically request SObject type when data export from an SObject record [feature 45](https://github.com/tprouvot/Salesforce-Inspector-reloaded/issues/45)

## Version 1.19

Expand Down
5 changes: 4 additions & 1 deletion addon/data-import.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import { DescribeInfo, copyToClipboard, initScrollTable } from "./data-load.js";

class Model {

constructor(sfHost) {
constructor({sfHost, args}) {
this.sfHost = sfHost;
this.importData = undefined;
this.consecutiveFailures = 0;
Expand Down Expand Up @@ -35,6 +35,9 @@ class Model {
Succeeded: true,
Failed: true
};
if (args.has("sobject")) {
this.importType = args.get("sobject");
}
if (localStorage.getItem(sfHost + "_isSandbox") != "true") {
//change background color for production
document.body.classList.add("prod");
Expand Down
4 changes: 2 additions & 2 deletions addon/inspect.js
Original file line number Diff line number Diff line change
Expand Up @@ -235,9 +235,9 @@ class Model {
if (!objectName) {
return undefined;
}
let query = "select Id from " + objectName;
let query = "SELECT Id FROM " + objectName;
if (this.recordData && this.recordData.Id) {
query += " where Id = '" + this.recordData.Id + "'";
query += " WHERE Id = '" + this.recordData.Id + "'";
}
return this.dataExportUrl(query);
}
Expand Down
64 changes: 49 additions & 15 deletions addon/popup.js
Original file line number Diff line number Diff line change
Expand Up @@ -49,14 +49,43 @@ function initLinks({sfHost}){
class App extends React.PureComponent {
constructor(props) {
super(props);
let {sfHost} = this.props;
let hostArg = new URLSearchParams();
hostArg.set("host", sfHost);
this.state = {
isInSetup: false,
contextUrl: null,
apiVersionInput: apiVersion
apiVersionInput: apiVersion,
exportHref: "data-export.html?" + hostArg,
importHref: "data-import.html?" + hostArg,
limitsHref: "limits.html?" + hostArg
};
this.onContextUrlMessage = this.onContextUrlMessage.bind(this);
this.onShortcutKey = this.onShortcutKey.bind(this);
this.onChangeApi = this.onChangeApi.bind(this);
this.onContextRecordChange = this.onContextRecordChange.bind(this);
}
onContextRecordChange(e) {
let {sfHost} = this.props;
let limitsArg = new URLSearchParams();
let exportArg = new URLSearchParams();
let importArg = new URLSearchParams();
exportArg.set("host", sfHost);
importArg.set("host", sfHost);
limitsArg.set("host", sfHost);
if (e.contextSobject) {
let query = "SELECT Id FROM " + e.contextSobject;
if (e.contextRecordId) {
query += " WHERE Id = '" + e.contextRecordId + "'";
}
exportArg.set("query", query);
importArg.set('sobject', e.contextSobject)
}
this.setState({
exportHref: "data-export.html?" + exportArg,
importHref: "data-import.html?" + importArg,
limitsHref: "limits.html?" + limitsArg
})
}
onContextUrlMessage(e) {
if (e.source == parent && e.data.insextUpdateRecordId) {
Expand All @@ -66,6 +95,7 @@ class App extends React.PureComponent {
contextUrl: locationHref
});
}

}

onShortcutKey(e) {
Expand Down Expand Up @@ -151,7 +181,7 @@ class App extends React.PureComponent {
inInspector,
addonVersion
} = this.props;
let {isInSetup, contextUrl, apiVersionInput} = this.state;
let {isInSetup, contextUrl, apiVersionInput, exportHref, importHref, limitsHref} = this.state;
let clientId = localStorage.getItem(sfHost + "_clientId");
let orgInstance = this.getOrgInstance(sfHost);
let hostArg = new URLSearchParams();
Expand Down Expand Up @@ -179,16 +209,16 @@ class App extends React.PureComponent {
)
),
h("div", {className: "main"},
h(AllDataBox, {ref: "showAllDataBox", sfHost, showDetailsSupported: !inLightning && !inInspector, linkTarget, contextUrl}),
h(AllDataBox, {ref: "showAllDataBox", sfHost, showDetailsSupported: !inLightning && !inInspector, linkTarget, contextUrl, onContextRecordChange: this.onContextRecordChange}),
h("div", {className: "slds-p-vertical_x-small slds-p-horizontal_x-small slds-border_bottom"},
h("div", {className: "slds-m-bottom_xx-small"},
h("a", {ref: "dataExportBtn", href: "data-export.html?" + hostArg, target: linkTarget, className: "page-button slds-button slds-button_neutral"}, h("span", {}, "Data ", h("u", {}, "E"), "xport"))
h("a", {ref: "dataExportBtn", href: exportHref, target: linkTarget, className: "page-button slds-button slds-button_neutral"}, h("span", {}, "Data ", h("u", {}, "E"), "xport"))
),
h("div", {className: "slds-m-bottom_xx-small"},
h("a", {ref: "dataImportBtn", href: "data-import.html?" + hostArg, target: linkTarget, className: "page-button slds-button slds-button_neutral"}, h("span", {}, "Data ", h("u", {}, "I"), "mport"))
h("a", {ref: "dataImportBtn", href: importHref, target: linkTarget, className: "page-button slds-button slds-button_neutral"}, h("span", {}, "Data ", h("u", {}, "I"), "mport"))
),
h("div", {},
h("a", {ref: "limitsBtn", href: "limits.html?" + hostArg, target: linkTarget, className: "page-button slds-button slds-button_neutral"}, h("span", {}, "Org ", h("u", {}, "L"), "imits"))
h("a", {ref: "limitsBtn", href: limitsHref, target: linkTarget, className: "page-button slds-button slds-button_neutral"}, h("span", {}, "Org ", h("u", {}, "L"), "imits"))
),
),
h("div", {className: "slds-p-vertical_x-small slds-p-horizontal_x-small"},
Expand Down Expand Up @@ -268,7 +298,8 @@ class AllDataBox extends React.PureComponent {
constructor(props) {
super(props);
this.SearchAspectTypes = Object.freeze({sobject: "sobject", users: "users", shortcuts: "shortcuts"}); //Enum. Supported aspects

let {onContextRecordChange} = props;
this.onContextRecordChange = onContextRecordChange;
this.state = {
activeSearchAspect: this.SearchAspectTypes.sobject,
sobjectsList: null,
Expand Down Expand Up @@ -315,11 +346,13 @@ class AllDataBox extends React.PureComponent {
let recordId = getRecordId(contextUrl);
let path = getSfPathFromUrl(contextUrl);
let sobject = getSobject(contextUrl);
this.setState({
let context = {
contextRecordId: recordId,
contextPath: path,
contextSobject: sobject
});
};
this.setState(context);
this.onContextRecordChange(context);
}
}

Expand Down Expand Up @@ -1587,9 +1620,9 @@ function getRecordId(href) {

if (url.pathname == "/one/one.app") {
// Pre URL change: https://docs.releasenotes.salesforce.com/en-us/spring18/release-notes/rn_general_enhanced_urls_cruc.htm
match = url.hash.match(/\/sObject\/([a-zA-Z0-9]+)(?:\/|$)/);
match = url.hash.match(/\/sObject\/([a-zA-Z0-9]{15}|[a-zA-Z0-9]{18})(?:\/|$)/);
} else {
match = url.pathname.match(/\/lightning\/[r|o]\/[a-zA-Z0-9_]+\/([a-zA-Z0-9]+)/);
match = url.pathname.match(/\/lightning\/[r|o]\/[a-zA-Z0-9_]+\/([a-zA-Z0-9]{15}|[a-zA-Z0-9]{18})/);
}
if (match) {
return match[1];
Expand All @@ -1613,10 +1646,11 @@ function getRecordId(href) {

function getSobject(href) {
let url = new URL(href);
if (url.pathname && url.pathname.endsWith("/list")){
let sobject = url.pathname.substring(0, url.pathname.lastIndexOf("/list"));
sobject = sobject.substring(sobject.lastIndexOf("/") + 1);
return sobject;
if (url.pathname) {
let match = url.pathname.match(/\/lightning\/[r|o]\/([a-zA-Z0-9_]+)\/[a-zA-Z0-9]+/);
if (match) {
return match[1];
}
}
return null;
}
Expand Down

0 comments on commit 25bfbdc

Please sign in to comment.