Newer Version Available
Context
When you add your canvas app as a connected app in Salesforce, you can retrieve
information about the current environment by using the Context object. The Context
object provides information to your app about how and by whom it’s being
consumed. You can use this information to make subsequent calls for information and
code your app so that it appears completely integrated with the Salesforce user
interface. This object is returned in JSON format and contains the following objects:
- Application—Information about the canvas app, such as version, access method, URL, and so on.
- Environment—Information about the environment, such as location, UI theme, and so on.
- Links—Links, such as the metadata URL, user URL, Chatter groups URL, and so on. You can use these links to make calls into Salesforce from your app.
- Organization—Information about the organization, such as name, ID, currency code, and so on.
- User—Information about the currently logged-in user, such as locale, name, user ID, email, and so on.
1"context":{
2 "application":
3 {
4 "applicationId":"06Px000000003ed",
5 "authType":"SIGNED_REQUEST",
6 "canvasUrl":"http://MyDomainName.my.salesforce.com:8080
7 /canvas_app_path/canvas_app.jsp",
8 "developerName":"my_java_app",
9 "isInstalledPersonalApp": false,
10 "name":"My Java App",
11 "namespace":"org_namespace",
12 "options":[],
13 "referenceId":"09HD00000000AUM",
14 "samlInitiationMethod": "None",
15 "version":"1.0.0"
16 },
17 "user":
18 {
19 "accessibilityModeEnabled":false,
20 "currencyISOCode":"USD",
21 "email":"admin@6457617734813492.com",
22 "firstName":"Sean",
23 "fullName":"Sean Forbes",
24 "isDefaultNetwork":false,
25 "language":"en_US",
26 "lastName":"Forbes",
27 "locale":"en_US",
28 "networkId":"0DBxx000000001r",
29 "profileId":"00ex0000000jzpt",
30 "profilePhotoUrl":"/profilephoto/005/F",
31 "profileThumbnailUrl":"/profilephoto/005/T",
32 "roleId":null,
33 "siteUrl":"https://SitesSubdomainName.secure.force.com/",
34 "siteUrlPrefix":"/mySite",
35 "timeZone":"America/Los_Angeles",
36 "userId":"005x0000001SyyEAAS",
37 "userName":"admin@6457617734813492.com",
38 "userType":"STANDARD"
39 },
40 "environment":
41 {
42 "parameters":{},
43 "dimensions":
44 {
45 "clientHeight": "50px",
46 "clientWidth": "70px",
47 "height":"900px",
48 "width":"800px",
49 "maxHeight":"2000px",
50 "maxWidth":"1000px"
51
52 },
53 "record":
54 {
55 "attributes":
56 {
57 "type":"Account",
58 "url":"/services/data/v51.0/sobjects/Account/001xx000003DGWiAAO"
59 },
60 "Id":"001xx000003DGWiAAO",
61 "Phone":"(555) 555-5555",
62 "Fax":"(555) 555-5555",
63 "BillingCity":"Seattle"
64 },
65 "displayLocation":"Chatter",
66 "locationUrl":"http://MyDomainName.my.salesforce.com:8080/canvas_app_path",
67 "subLocation":null,
68 "uiTheme":"Theme3",
69 "version":
70 {
71 "api":"51.0",
72 "season":"SUMMER"
73 }
74 },
75 "organization":
76 {
77 "currencyIsoCode":"USD",
78 "multicurrencyEnabled":true,
79 "name":"Edge Communications",
80 "namespacePrefix":"org_namespace",
81 "organizationId":"00Dx00000001hxyEAA"
82 },
83 "links":
84 {
85 "chatterFeedItemsUrl":"/services/data/v51.0/chatter/feed-items",
86 "chatterFeedsUrl":"/services/data/v51.0/chatter/feeds",
87 "chatterGroupsUrl":"/services/data/v51.0/chatter/groups",
88 "chatterUsersUrl":"/services/data/v51.0/chatter/users",
89 "enterpriseUrl":"/services/Soap/c/51.0/00Dx00000001hxy",
90 "loginUrl":"http://MyDomain.my.salesforce.com",
91 "metadataUrl":"/services/Soap/m/51.0/00Dx00000001hxy",
92 "partnerUrl":"/services/Soap/u/51.0/00Dx00000001hxy",
93 "queryUrl":"/services/data/v51.0/query/",
94 "restUrl":"/services/data/v51.0/",
95 "recentItemsUrl":"/services/data/v51.0/recent/",
96 "searchUrl":"/services/data/v51.0/search/",
97 "sobjectUrl":"/services/data/v51.0/sobjects/",
98 "userUrl":"/005x0000001SyyEAAS"
99 }
100}You can request Salesforce exclude portions of the context data that you don’t need. To control the amount of data that’s excluded, you must implement your own Canvas.CanvasLifecycleHandler in Apex and provide a list of excluded context sections in your implementation of excludeContextTypes().