You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: README.md
+8-6Lines changed: 8 additions & 6 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -1,6 +1,6 @@
1
1
# Pure JS Buttons in Lightning
2
2
3
-
JS buttons are back in Lightning! (For now, at least) And they are even more powerful than JS buttons in classic, in some respects. SOQL and DML statements supported!
3
+
JS buttons are back in Lightning! (For now, at least) And they are even more powerful than JS buttons in classic. Run SOQL and DML statements seamlessly. Make callouts to APIs, including Salesforce APIs using named credentials directly from JavaScript! This would allow you to build buttons that do amazing things, just using JavaScript. Check out the `scripts` folder for examples. Feel free to raise a PR to contribute your own scripts.
* Upsert and Update statements must be qualified with the SObjectType thus `|| insert Account(accts) ||;`
48
50
* SOQL statements are parsed using template literals. Any arguments should follow the appropriate syntax `${argument}`
49
51
* SOQL and DML statements may not be wrapped in a function.
52
+
* All statements must be strictly terminated by a semicolon.
50
53
51
54
### Known Limitations
52
55
53
56
* Support for delete has been intentionally withheld.
54
57
* Single-line comments are not supported.
55
58
* Haven't tested DML with date, datetime, boolean, geolocation and other compound fields. I will update this section as I do so.
56
-
*Explicit use of async/await, Promises and Generators is not supported, atm.
59
+
*SOQL and DML statements should be enclosed in async functions, if they are required to be contained in functions. The program automatically adds `await` to SOQL and DML statements
57
60
* DML on Files, Attachments, Documents, etc. is not supported
58
61
59
-
### For Developers: Extending to more than one Button per SObjectType
60
-
61
-
If you need more than one button on an SObjectType, you may create a lightning component quickAction with the name of the custom metadata record containing your JS passed in to the `jsButton` child component. You will also need to implement an `init` method to invoke the controller method in `jsButton`. Refer to the `jsButtonQuickAction` component for implementation details
62
+
### Using Salesforce (and other) APIs in your script
62
63
64
+
You can use any of Salesforce's APIs (REST, Tooling, Metadata) by setting up a named credential for your own Salesforce instance. This allows you to write scripts for admins to perform tasks like [deleting inactive versions of flows](scripts/jsButton/deleteInactiveFlowVersions.js), or [creating new JS Buttons](scripts/jsButton/createNewJSButton.js)! You can also use named credentials to interact with other APIs as well, of course. Although, for Public APIs, you can just use `fetch` directly. The Salesforce named credential set up would need to have the following scopes (api refresh_token offline_access web). You would need to set up your own Connected App and a Salesforce Auth. Provider that uses this connected app.
0 commit comments