-
Notifications
You must be signed in to change notification settings - Fork 10
Expand file tree
/
Copy pathDeveloperConsoleFix.page
More file actions
96 lines (80 loc) · 3.92 KB
/
Copy pathDeveloperConsoleFix.page
File metadata and controls
96 lines (80 loc) · 3.92 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
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
<apex:page docType="html-5.0" id="thepage">
<script src="//cdnjs.cloudflare.com/ajax/libs/jsforce/1.7.0/jsforce.min.js"></script>
<p>
Yes, "Delete my IDEWorkspace" sounds a little scary. But that's actually what this script will do.
The developer console state is maintained in a record in table IDEWorkspace.
When that record is deleted, there is no state. If the dev
console decides to save something, it notices that and creates a new record.
</p>
<p>
This is not really documented anywhere. You can learn a little bit by reading
the Salesforce help article <a href="https://help.salesforce.com/articleView?id=000205964&language=en_US&type=1">Developer Console menus not working</a>
The API we are using is the
<a href="https://developer.salesforce.com/docs/atlas.en-us.api_tooling.meta/api_tooling/">Tooling API</a>.
The documentation merely notes that "The following
Tooling API objects are used internally by the Developer Console."
</p>
<apex:form id="theform">
<apex:pageblock id="thepageblock">
<apex:pageblockButtons location="top" id="buttons">
<apex:commandButton value="Delete my IDEWorkpace"
onclick="deleteIDEWorkspace()"
disabled="True"
id="deletebutton"
/>
</apex:pageblockButtons>
<apex:pageBlockSection id="section">
<apex:pageblocksectionitem id="item1">
<apex:outputlabel value="IDEWorkspace ID:" styleclass="bold"/>
<apex:outputtext value="not found" id="IdDisplay" />
</apex:pageblocksectionitem>
</apex:pageBlockSection>
</apex:pageblock>
</apex:form>
<apex:outputPanel id="emptypanel">
</apex:outputPanel>
<script>
var conn = new jsforce.Connection({ accessToken: '{!$Api.Session_Id}' });
var workspaceId;
var deleted = false;
var button = document.getElementById('{!$Component.thepage.theform.thepageblock.buttons.deletebutton}');
var notFoundMessage = 'No IDEWorkspace found for your user';
var idDisplay = document.getElementById('{!$Component.thepage.theform.thepageblock.section.item1.IdDisplay}');
conn.tooling.query("select id, name, createdbyid from ideworkspace where createdbyid = '{!$User.Id}'",
function(err, result) {
if (err) { alert(err); }
else if (result.totalSize > 1) {
alert('Query returned multiple IDEWorkspaces ' + JSON.stringify(result));
}
else if (result.totalSize < 1) {
idDisplay.innerHTML = notFoundMessage;
}
else {
// exactly one IDEWorkspace found for this user
workspaceId = result.records[0].Id;
console.log(workspaceId);
button.className = "btn";
button.disabled = false;
document.getElementById('{!$Component.thepage.theform.thepageblock.section.item1.IdDisplay}').innerHTML = workspaceId;
}
});
function deleteIDEWorkspace() {
conn.tooling.query("select id, name, createdbyid from ideworkspace where createdbyid = '{!$User.Id}'",
function(err, result) {
if (err) { alert(err); }
else if (result.totalSize > 1) {alert('Query returned multiple IDEWorkspaces ' + JSON.stringify(result));}
else if (result.totalSize < 1) {alert('Could not determine Id of your IDEWorkspace');}
else {
console.log(workspaceId);
console.log("deleting...");
conn.tooling.sobject('IDEWorkspace').delete(workspaceId, function(err, ret) {
if (err || !ret.success) { return console.error(err, ret); }
alert('Deleted IDEWorkspace Successfully : ' + ret.id);
button.className = "btnDisabled";
button.disabled = false;
});
}
});
}
</script>
</apex:page>