0

I'm using canvas app from visualforce page. During the communication, when button clicked in the page, it publish event, and this should cause the canvas to create attachment(s) in SF.

But I'm keep getting error, which is from SF script:

Uncaught TypeError: this.getUrlParameters is not a function

at Object.generateQueryString (CanvasProxy.js:17) at Function.request (CanvasProxy.js:21) at Object.ajax (CanvasProxy.js:135) at O (CanvasProxy.js:91) at g (CanvasProxy.js:30)

I assume it's related to the parameters in the ajax, because I'm able to call other rest method + I run this rest with same input from workbench and it worked.
Any idea?

Sfdc.canvas.client.refreshSignedRequest(function(data){ 
if(data.status === 200){ 
    var signedRequest = data.payload.response; 
    var part = signedRequest.split('.')[1]; 
    var obj = JSON.parse(Sfdc.canvas.decode(part)); 
    Sfdc.canvas.client.subscribe( 
        obj.client, {
            name: 'myapp1.testEvent' , 
            onData : function(inp){ 
                try{ 
                    console.log(inp); 
                    Sfdc.canvas.client.ajax(
                        obj.context.links.restUrl + 'composite/tree/Attachment/', 
                        { 
                            client : obj.client, 
                            method : 'POST', 
                            headers : { "Authorization" : "OAuth " + obj.client.oauthToken, "Content-Type" : "application/json" }, 
                            data : { "records": [{"attributes" : {"type" : "Attachment", "referenceId" : "ref1"}, "name" : "test1234", "parentId" : "a040O00000Xd4rp" ,"Body" : "tset1"}]}, 
                            success : function(data) { alert("Status: " + data.status); } 
                        } 
                    ); 
                }
                catch(err){
                    alert(err);
                } 
            }
        } 
    ); 
    }
}
);

1 Answer 1

0

Solved by changing the code

var body = {records : [{"attributes" : {"type" : "Attachment", "referenceId" : "ref1"}, "name" : "test1234", "parentId" : "a040O00000Xd4rp" ,"Body" : "tset1"}]}; 
    Sfdc.canvas.client.ajax(
        obj.context.links.restUrl + 'composite/tree/Attachment/', 
        { 
            client : obj.client, 
            method : 'POST', 
            headers : { 
                "Authorization" : "OAuth " + obj.client.oauthToken, 
            }, 
            data: JSON.stringify(body), 
            success : function(data) { 
                alert("Status: " + data.status); 
            } 
        } 
    ); 

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .