-
Notifications
You must be signed in to change notification settings - Fork 15
/
CloseOpportunity.vfp
31 lines (25 loc) · 1.15 KB
/
CloseOpportunity.vfp
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
//--the page loads data using the standard controller, ------//
//--but updates it with Remote Objects, combining two different data access methods on the same page.-------//
<apex:page docType="html-5.0" standardController="Opportunity" title="Close Opportunity">
<script src='/canvas/sdk/js/publisher.js'></script>
<apex:remoteObjects>
<apex:remoteObjectModel name="Opportunity" fields="Id,Name"/>
</apex:remoteObjects>
<div class="mypage">
<button onclick="closeOpportunity('Closed Won')">Won</button>
<button onclick="closeOpportunity('Closed Lost')">Lost</button>
</div>
<script>
var opportunityId = "{!Opportunity.Id}";
function closeOpportunity(stageName) {
var opportunity = new SObjectModel.Opportunity();
opportunity.update([opportunityId], {StageName: stageName}, function(error, records) {
if (error) {
alert(error.message);
} else {
Sfdc.canvas.publisher.publish({ name: "publisher.close", payload: {refresh:"true"}});
}
});
}
</script>
</apex:page>