function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
VineetzVineetz 

Unable to call Salesforce Canvas ajax using Sfdc.canvas.client.ajax

Hey all,

I have an app hosted on heroku that is trying to access Salesforce data layer.
I am trying to user Sfdc.canvas.client.ajax but im unable to get neither a SUCCESS or FAILURE from this call.
I also am not facing any error.

Please find my code below :
________________________________________________________________________
I HAVE ADDED THE FOLLOWING LIBRARIES : 
________________________________________________________________________

            <script type="text/javascript" src="/sdk/js/canvas-all.js"></script>
            <script type="text/javascript" src="/sdk/js/client.js"></script>
            <script type="text/javascript" src="/sdk/js/xd.js"></script>
            <script type="text/javascript" src="/sdk/js/oauth.js"></script>
            <script type="text/javascript" src="/sdk/js/cookies.js"></script>
            <script type="text/javascript" src="/scripts/json2.js"></script>
            <script type="text/javascript" src="/scripts/chatter-talk.js"></script>

____________________________________________________________________________________________

AJAX CALL : 
_____________________________________________________________________________________________
                        /* VIN */
                        function doFunction(){
                            var sr = JSON.parse('<%=signedRequestJson%>');
                            alert(Object.values(sr));
                            alert(JSON.stringify(sr, undefined, 2));
                            alert(JSON.stringify(sr.client.oauthToken, undefined, 2));
                            console.debug('xaxa' + Object.values(sr));
                            console.log("XAXA" + Object.values(sr));
                            //var sizes = Sfdc.canvas.client.size();
                            //alert('CLIENT SIZE' + sizes);
                            var csId =sr.context.environment.parameters.contactid;
                            alert('csID' + csId);
                            //Creating a variable with query Structure
                            var queryUrl= sr.context.links.queryUrl+"?q=SELECT+id+from+Contact+where+id='"+csId+"'"; 
                            //var xaxaurl = sr.context.links.queryUrl+"?q=SELECT+ID,NAME+FROM+CASE";
                            alert('QUERYCALL' + queryUrl );
                            //alert('OOGA WOOGA  BOOGA' );
                            
                            // Below block makes an AJAX call to Salesforce
                            
                            Sfdc.canvas.client.ajax(queryUrl,
                            { client : sr.client, //Send the req to signed request Client which has the OAuth – The Same request that requested Post to TMG - reused
                                method: 'GET', // GET method will request the fetched record details back from Salesforce
                                contentType: "application/json",
                                token : sr.client.oauthToken,
                                success : function(data) {
                                    alert('SUCCESS');
                                    console.debug("SUCCESS");
                                    console.log("SUCCESS");
                                },
                                failure : function(error) {
                                    alert('FAILURE');
                                    console.debug("SUCCESS");
                                    console.log("SUCCESS");

                                }
                            });
                        }

Please let me know if theres anything wrong that i'm doing ? anything missing from my end ?

Also can anyone provide me a link with the latest SDK with all the JS libraries (THE SDK in Canvas framework on github doesnt have the libraries)
Any help is appreciated.

I am also seeing the following errors when I inspect browser : 

Unrecognized Content-Security-Policy directive 'referrer'.

b @ SfdcSessionBase204.js:31
updateExpires @ SfdcSessionBase204.js:34
e @ SfdcSessionBase204.js:35
t @ SfdcCore.js:220
SfdcFramework.b.require @ SfdcCore.js:234
(anonymous) @ SfdcSessionBase204.js:36
(anonymous) @ SfdcSessionBase204.js:36
sessionserver204.html:1 Unrecognized Content-Security-Policy directive 'reflected-xss'.


errors in SfdcSessionBase204.js:36  :
LINE NO 36 : 
!c||!f){if(k.push(a.id),!c&&!f){a=e.document;c=a.createElement("iframe");c.setAttribute("title","sessionserver");var b=c.style;b.position="absolute";b.left=b.top="-999px";e.addEventListener?e.addEventListener("message",l,!1):e.attachEvent&&e.attachEvent("onmessage",l);a.body.appendChild(c);c.src=h}}else f.postMessage(Sfdc.JSON.stringify(m(a)),h)}var q=!1;try{q=!!e.localStorage}catch(s){console.log("Can't access local storage: "+s)}var n=!(e.postMessage&&q),c=null,f=null,g={},p=0,k=[];Sfdc.provide("SfdcApp.SfdcSession",