Skip to content

Commit

Permalink
[show-all-data] Add custom header for create update (#199)
Browse files Browse the repository at this point in the history
  • Loading branch information
tprouvot authored Jan 5, 2024
1 parent ce14fe2 commit 9d7cd11
Show file tree
Hide file tree
Showing 4 changed files with 44 additions and 4 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 @@

## Version 1.22

- Allow users to define REST callout headers on showAllData page. The need is to prevent the auto assignation of Accounts, Cases and Leads. [feature 198](https://github.com/tprouvot/Salesforce-Inspector-reloaded/issues/198) (issue by [SfdxDieter](https://github.com/SfdxDieter)
- Fix flow scrollability] checkbox on non dev environments [issue 258](https://github.com/tprouvot/Salesforce-Inspector-reloaded/issues/258) (by [Samuel Krissi](https://github.com/samuelkrissi))
- Fix 'Record Type not displayed' in popup [issue 255](https://github.com/tprouvot/Salesforce-Inspector-reloaded/issues/255)
- Add "Options" page to manage local storage variables directly from the UX. Allow to reposition the popup button [feature 145](https://github.com/tprouvot/Salesforce-Inspector-reloaded/issues/145) (contribution by [Pietro Martino](https://github.com/pietromartino))
Expand Down
5 changes: 3 additions & 2 deletions addon/inspect.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ class Model {
this.detailsFilter = "";
this.detailsBox = null;
this.editMode = null; // null (when not editing), "update", "delete" (for confirming) or "create"
this.headerCallout = localStorage.getItem("createUpdateRestCalloutHeaders") ? JSON.parse(localStorage.getItem("createUpdateRestCalloutHeaders")) : "{}";
this.hasEntityParticles = false;
this.objectActionsOpen = false;
this.objectSetupLinks = null;
Expand Down Expand Up @@ -148,7 +149,7 @@ class Model {
let recordUrl = this.objectData.urls.rowTemplate.replace("{ID}", this.recordData.Id);
this.spinFor(
"saving record",
sfConn.rest(recordUrl, {method: "PATCH", body: record}).then(() => {
sfConn.rest(recordUrl, {method: "PATCH", body: record, headers: this.headerCallout}).then(() => {
this.endEdit();
this.clearRecordData();
this.setRecordData(sfConn.rest(recordUrl));
Expand All @@ -175,7 +176,7 @@ class Model {
let recordUrl = this.objectData.urls.sobject;
this.spinFor(
"creating record",
sfConn.rest(recordUrl, {method: "POST", body: record}).then(result => {
sfConn.rest(recordUrl, {method: "POST", body: record, headers: this.headerCallout}).then(result => {
this.endEdit();
let args = new URLSearchParams();
args.set("host", this.sfHost);
Expand Down
32 changes: 30 additions & 2 deletions addon/options.js
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,8 @@ class OptionsTabSelector extends React.Component {
title: "API",
content: [
{option: APIVersionOption, key: 1},
{option: APIKeyOption, key: 2}
{option: APIKeyOption, key: 2},
{option: RestHeaderOption, key: 3}
]
},
{
Expand Down Expand Up @@ -158,7 +159,6 @@ class ArrowButtonOption extends React.Component {
onChangeArrowOrientation(e) {
let orientation = e.target.value;
this.setState({arrowButtonOrientation: orientation});
console.log("[SFInspector] Setting Arrow Orientation: ", orientation);
localStorage.setItem("popupArrowOrientation", orientation);
window.location.reload();
}
Expand Down Expand Up @@ -229,6 +229,34 @@ class APIVersionOption extends React.Component {
}
}

class RestHeaderOption extends React.Component {

constructor(props) {
super(props);
this.onChangeRestHeader = this.onChangeRestHeader.bind(this);
this.state = {restHeader: localStorage.getItem("createUpdateRestCalloutHeaders") ? localStorage.getItem("createUpdateRestCalloutHeaders") : ""};
}

onChangeRestHeader(e) {
let restHeader = e.target.value;
this.setState({restHeader});
localStorage.setItem("createUpdateRestCalloutHeaders", restHeader);
}

render() {
return h("div", {className: "slds-grid slds-border_bottom slds-p-horizontal_small slds-p-vertical_xx-small"},
h("div", {className: "slds-col slds-size_4-of-12 text-align-middle"},
h("span", {}, "Rest Header")
),
h("div", {className: "slds-col slds-size_2-of-12 slds-form-element slds-grid slds-grid_align-end slds-grid_vertical-align-center slds-gutters_small"},
h("div", {className: "slds-form-element__control slds-col slds-size_6-of-12"},
h("input", {type: "text", id: "restHeaderInput", className: "slds-input", placeholder: "Rest Header", value: this.state.restHeader, onChange: this.onChangeRestHeader}),
)
)
);
}
}

class FlowScrollabilityOption extends React.Component {

constructor(props) {
Expand Down
10 changes: 10 additions & 0 deletions docs/how-to.md
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,16 @@ You can enable this view for the Shortcut search by creating a new localVariable

Then when you click on a PermissionSet / PermissionSetGroups search result, you'll be redirected to the summary.

## Customize Create / Update rest callout headers (to prevent execution of auto assignment rules for Accounts, Cases, or Leads)

[Assignment Rule Header](https://developer.salesforce.com/docs/atlas.en-us.api_rest.meta/api_rest/headers_autoassign.htm)

From the popup, click on "Options" button and select the API tab.

<img width="846" alt="image" src="https://github.com/tprouvot/Salesforce-Inspector-reloaded/assets/35368290/fba23a19-0b11-4275-b4d9-52e9e6ac1bd9">

If you want to prevent auto assignment rules, set the `createUpdateRestCalloutHeaders` property to `{"Sforce-Auto-Assign" : false}`

## Update API Version

Since the plugin's api version is only updated when all productions have been updated to the new release, you may want to use the latest version during preview windows.
Expand Down

0 comments on commit 9d7cd11

Please sign in to comment.