-
Notifications
You must be signed in to change notification settings - Fork 5
Expand file tree
/
Copy pathcreateNewJSButton.js
More file actions
50 lines (50 loc) · 1.76 KB
/
createNewJSButton.js
File metadata and controls
50 lines (50 loc) · 1.76 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
try {
let cmpName = prompt(
"Enter the name for your aura bundle. This will be the name of the custom metadata record backing this bundle as well"
);
if (!cmpName) return;
let body = {
MasterLabel: cmpName,
Description: "created by js button",
ApiVersion: 48.0,
DeveloperName: cmpName
};
let resp = await callout(
"callout:salesforce/services/data/v48.0/tooling/sobjects/AuraDefinitionBundle/",
"POST",
{ "Content-Type": "application/json" },
body
);
let auraBundleId = JSON.parse(resp.body).id;
alert(auraBundleId);
let source = ` <aura:component implements="force:lightningQuickActionWithoutHeader,force:hasRecordId,force:hasSObjectName"> <c:jsButtonLwc aura:id="jsbutton" recordId="{!v.recordId}" cmdtName="${cmpName}" oninitcomplete="{!c.doInit}" ></c:jsButtonLwc> </aura:component>`;
body = {
AuraDefinitionBundleId: auraBundleId,
DefType: "COMPONENT",
Format: "XML",
Source: source
};
resp = await callout(
"callout:salesforce/services/data/v48.0/tooling/sobjects/AuraDefinition/",
"POST",
{ "Content-Type": "application/json" },
body
);
alert(resp.statusCode);
source = ` ({ doInit: function (component) { component .find("jsbutton") .invoke() .then( $A.getCallback((resp) => { $A.get("e.force:closeQuickAction").fire(); })) .catch( $A.getCallback((err) => { $A.get("e.force:closeQuickAction").fire(); })); } });`;
body = {
AuraDefinitionBundleId: auraBundleId,
DefType: "CONTROLLER",
Format: "JS",
Source: source
};
resp = await callout(
"callout:salesforce/services/data/v48.0/tooling/sobjects/AuraDefinition/",
"POST",
{ "Content-Type": "application/json" },
body
);
toast(resp.statusCode, "success");
} catch (e) {
toast(JSON.stringify(e), "error");
}