This repository has been archived by the owner on Jan 10, 2024. It is now read-only.
/
DurablePushTopicStreamingDemo.page
executable file
·90 lines (80 loc) · 3.59 KB
/
DurablePushTopicStreamingDemo.page
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
<apex:page controller="DurablePushTopicStreamingController" action="{!getOrCreatePushChannel}">
<apex:includeScript value="{!$Resource.jquery}"/>
<script>
var $j = jQuery.noConflict();
function getBaseAccountSobjectUrl() {
return window.location.protocol+'//'+window.location.hostname+ (null != window.location.port ? (':'+window.location.port) : '') +
'/services/data/v37.0/sobjects/Account/'
}
function generateEvents(msgInputId, sessionId) {
var payload = {};
payload.name = document.getElementById(msgInputId).value;
var createResult = $j.ajax({
async: false,
url: getBaseAccountSobjectUrl(),
headers: {
'Authorization': 'OAuth ' + sessionId
},
type: "POST",
data: JSON.stringify(payload),
contentType: "application/json; charset=utf-8",
dataType: "json"
});
if (createResult.status == 201) {
updateAccount(payload, JSON.parse(createResult.responseText).id, sessionId);
}
}
function updateAccount(payload, accountId, sessionId) {
payload.name = payload.name + '_UPDATED';
var updateResult = $j.ajax({
async: false,
url: getBaseAccountSobjectUrl() + accountId,
headers: {
'Authorization': 'OAuth ' + sessionId
},
type: "PATCH",
data: JSON.stringify(payload),
contentType: "application/json; charset=utf-8",
dataType: "json"
});
if (updateResult.status == 204) {
deleteAccount(accountId, sessionId);
}
}
function deleteAccount(accountId, sessionId) {
return $j.ajax({
async: false,
url: getBaseAccountSobjectUrl() + accountId,
headers: {
'Authorization': 'OAuth ' + sessionId
},
type: "DELETE",
contentType: "application/json; charset=utf-8",
dataType: "json"
});
}
function sendPostRequest(payload, sessionId) {
}
</script>
<apex:pageBlock >
<apex:pageBlockSection title="Replay Settings">
<apex:form >
Channel: <strong><apex:outputText label="streaming push topic" value="{!channel}"/></strong><br/>
Replay From Id: <apex:inputText label="replay from" value="{!replayFrom}"/><br/>
(-2 = earliest, -1 = no replay)<br/>
<apex:commandButton reRender="StreamingReplay" value="Update Subscription"/>
</apex:form>
</apex:pageBlockSection>
<apex:pageBlockSection title="Generate DML Events">
<apex:form >
New Account Name: <apex:inputText id="accountName" label="name"/><br/>
<apex:commandButton onclick="generateEvents('{!$Component.accountName}', '{!$Api.Session_ID}'); return false;" value="Create, Update, Delete New Account" />
</apex:form>
</apex:pageBlockSection>
</apex:pageBlock>
<apex:pageBlock title="Notifications">
<apex:outputPanel id="StreamingReplay" >
<c:DurablePushTopicEventDisplay channel="{!channel}" replayFrom="{!replayFrom}" />
</apex:outputPanel>
</apex:pageBlock>
</apex:page>