0

I developed Canvas web APP using Java and I have a JSP page that renders the page and a FORM that takes input text and submit button .

After I press the Submit ,which in turn call the javascript function on click and do the AJAX post call which is also working fine, but on post back when I tried to get the request parameters the signedRequest is NULL.

The same one is working on the intial load of the page first time but not on post back. I am testing the page in Canvas Preview.

 Map<String, String[]> parameters  = request.getParameterMap();
    String[] signedRequest = parameters.get("signed_request");

Thnaks.

0

Canvas passes this liquid object as "signed_object" parameter when you load a page. I guess when you are submitting the AJAX post call, your application is submitting the form and it is clearing all the params for last URL.

This is a very common scenario and that's why salesforce supports to regenerate this parameter. Refer below URL to regenerate this using Canvas SDK.

  // Gets a signed request on demand.

  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));
        }
    }

https://developer.salesforce.com/docs/atlas.en-us.platform_connect.meta/platform_connect/canvas_app_refresh_signed_request.htm

0

Thank You, it worked. I have one more thing to ask, I am doing POST and had the Apex class expose as rest service but I am getting 400 error. In debug logs I can see my do Post method was called and after that I could not see the debug line got executed. var sr = JSON.parse('<%=signedRequestJson%>'); var url = sr.client.instanceUrl + "/services/apexrest/Account/"; Sfdc.canvas.client.ajax(url, {client : sr.client, method: 'POST', contentType: "application/json", data: '{"name" : "Test Account" , "phone" : "1234567890"}', // Passing Accoutn name and phone success : function(data) { Sfdc.canvas.byId('arstatuspost').innerHTML = data.status;

@RestResource(urlMapping='/Account/*') global with sharing class AccountRestService{

@HttpPost global static String doPost(String name, String phone) { system.debug('In Post'); Account account = new Account(); account.Name = name; account.phone = phone;
insert account; return account.Id; } }

                   }

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.