Skip to content

Commit 25be9e4

Browse files
committed
First commit
0 parents  commit 25be9e4

33 files changed

+10385
-0
lines changed

.eslintignore

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
**/lwc/**/*.css
2+
**/lwc/**/*.html
3+
**/lwc/**/*.json
4+
**/lwc/**/*.svg
5+
**/lwc/**/*.xml
6+
.sfdx

.eslintrc.js

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
module.exports = {
2+
env: {
3+
browser: true,
4+
es6: true
5+
},
6+
extends: "eslint:recommended",
7+
globals: {
8+
Atomics: "readonly",
9+
SharedArrayBuffer: "readonly"
10+
},
11+
parserOptions: {
12+
ecmaVersion: 2018,
13+
sourceType: "module"
14+
},
15+
rules: {}
16+
};

.forceignore

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
# List files or directories below to ignore them when running force:source:push, force:source:pull, and force:source:status
2+
# More information: https://developer.salesforce.com/docs/atlas.en-us.sfdx_dev.meta/sfdx_dev/sfdx_dev_exclude_source.htm
3+
#
4+
5+
package.xml
6+
7+
# LWC configuration files
8+
**/jsconfig.json
9+
**/.eslintrc.json
10+
11+
# LWC Jest
12+
**/__tests__/**
13+
**/profiles/**
14+
**/flexipages/**
15+
**/layouts/Account*

.gitignore

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
# This file is used for Git repositories to specify intentionally untracked files that Git should ignore.
2+
# If you are not using git, you can delete this file. For more information see: https://git-scm.com/docs/gitignore
3+
# For useful gitignore templates see: https://github.com/github/gitignore
4+
5+
# Salesforce cache
6+
.sfdx/
7+
.localdevserver/
8+
9+
# LWC VSCode autocomplete
10+
**/lwc/jsconfig.json
11+
12+
# LWC Jest coverage reports
13+
coverage/
14+
15+
# Logs
16+
logs
17+
*.log
18+
npm-debug.log*
19+
yarn-debug.log*
20+
yarn-error.log*
21+
22+
# Dependency directories
23+
node_modules/
24+
25+
# Eslint cache
26+
.eslintcache
27+
28+
# MacOS system files
29+
.DS_Store
30+
31+
# Windows system files
32+
Thumbs.db
33+
ehthumbs.db
34+
[Dd]esktop.ini
35+
$RECYCLE.BIN/
36+
flexipages/

.prettierignore

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
# List files or directories below to ignore them when running prettier
2+
# More information: https://prettier.io/docs/en/ignore.html
3+
#
4+
5+
**/staticresources/**
6+
.localdevserver
7+
.sfdx
8+
9+
coverage/

.prettierrc

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
{
2+
"trailingComma": "none",
3+
"overrides": [
4+
{
5+
"files": "**/lwc/**/*.html",
6+
"options": { "parser": "lwc" }
7+
},
8+
{
9+
"files": "*.{cmp,page,component}",
10+
"options": { "parser": "html","printWidth":120 }
11+
}
12+
]
13+
}

.vscode/extensions.json

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
{
2+
"recommendations": [
3+
"salesforce.salesforcedx-vscode",
4+
"redhat.vscode-xml",
5+
"dbaeumer.vscode-eslint",
6+
"esbenp.prettier-vscode"
7+
]
8+
}

.vscode/launch.json

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
{
2+
// Use IntelliSense to learn about possible attributes.
3+
// Hover to view descriptions of existing attributes.
4+
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
5+
"version": "0.2.0",
6+
"configurations": [
7+
{
8+
"name": "Launch Apex Replay Debugger",
9+
"type": "apex-replay",
10+
"request": "launch",
11+
"logFile": "${command:AskForLogFileName}",
12+
"stopOnEntry": true,
13+
"trace": true
14+
}
15+
]
16+
}

.vscode/settings.json

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
{
2+
"search.exclude": {
3+
"**/node_modules": true,
4+
"**/bower_components": true,
5+
"**/.sfdx": true
6+
}
7+
}

README.md

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
# Pure JS button in Lightning
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!
4+
5+
### The Setup
6+
7+
The button can be made available to users via a quick action powered by the `jsButtonQuickAction` component. The actual JavaScript should be entered into a `JS_Button__mdt` custom metadata record, into the `Script__c` field with the same name as the name of the SObject. The repo contains a couple of samples for Account and Contact. The corollary is that, out of the box, only one button per SObjecttype may be supported.
8+
9+
### The syntax
10+
11+
This is the fun part. The syntax is quite permissive, with some restrictions, which I will cover below. I haven't, obviously, explored all possible scenarios and the information may still be incomplete. Please raise a PR if you come across something I haven't covered.
12+
13+
* Simple examples (no soql/dml)
14+
15+
```javascript
16+
alert('hello,world');
17+
```
18+
19+
```javascript
20+
alert(Array(5).fill(0).map((e,i)=>'Hello, '+i));
21+
```
22+
23+
* Fetch 10 of the 100 latest Accounts without a Contact and add a Contact to each of them
24+
25+
```javascript
26+
let accts=|| Select Name,(Select Id from Contacts) from Account order by createddate desc limit 100 ||;
27+
let contacts = accts.filter((a)=>!a.Contacts || a.Contacts.length===0).slice(0,10).map((a)=>({LastName: a.Name+'-Contact', AccountId: a.Id}));
28+
let contactIds = || insert Contact(contacts) ||; //Note how the SObjectType has been specified. This is required for insert and upsert
29+
$A.get('e.force:refreshView').fire(); // $A is supported!
30+
```
31+
32+
* Act in the context of the current record
33+
34+
```javascript
35+
let acct = || Select NumberOfEmployees from Account where Id='${recordId}' ||;
36+
acct[0].NumberOfEmployees = (acct[0].NumberOfEmployees || 0) + 10;
37+
let acctId = || update acct ||;
38+
acct = || Select NumberOfEmployees from Account where Id='${acctId}' ||;
39+
alert(acct[0].NumberOfEmployees);
40+
$A.get('e.force:refreshView').fire();
41+
```
42+
43+
44+
45+
### Developers: Extending to more than one button per SObject Type
46+
47+
If you need more, you may create lightning component quickActions 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 more details
48+

0 commit comments

Comments
 (0)