Referencing the Canvas SDK
Getting Context in Your Canvas App
Alternatives to Cookies for User Tracking
Debugging in a Canvas App
Using the <select> Tag in a Canvas App
Lightning Component Code Examples
Canvas Limits
Previous Versions
When you authenticate your canvas app using signed request, you get the CanvasRequest object (which contains the Context object) as part of the POST to the canvas app URL. If you’re authenticating using OAuth, or you want to make a call to get context information, you can do so by making a JavaScript call.
Getting context data from the Canvas SDK is the most reliable way to identify users. Browsers may not send your canvas app cookies or other identifying data. See Alternatives to Cookies for User Tracking.
Note
The following code sample is an example of a JavaScript call to get context. This code creates a link with the text “Get Context” which then calls the Sfdc.canvas.client.ctx function.
1<script>
2 function callback(msg) {
3 if (msg.status !== 200) {
4 alert("Error: " + msg.status);
5 return;
6 }
7 alert("Payload: ", msg.payload);
8 }
9
10 var ctxlink = Sfdc.canvas.byId("ctxlink");
11 var client = Sfdc.canvas.oauth.client();
12 ctxlink.onclick=function() {
13 Sfdc.canvas.client.ctx(callback, client)};
14 }
15</script>
16
17<a id="ctxlink" href="#">Get Context</a>See Also