You need to sign in to do that
Don't have an account?
Bobby Knezevic
Making an HTTP request to a Salesforce resource within a custom REST endpoint.
I'm struggling to understand what kind of restrictions are in place when making a HTTP request to a Salesforce resource within a custom REST endpoint. When I construct the request in a console as such ...
However, when I make the same call in a custom REST endpoint I get the following output:
\r\n<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.01 Transitional//EN\" \"http://www.w3.org/TR/html4/loose.dtd\">\n<html>\n<head>\n <meta HTTP-EQUIV=\"PRAGMA\" CONTENT=\"NO-CACHE\">\n\n\n\n\n\n<script>\nif (this.SfdcApp && this.SfdcApp.projectOneNavigator) { SfdcApp.projectOneNavigator.handleRedirect('https://evestment--dev.cs13.my.salesforce.com?ec=302&startURL=%2Fapex%2FInvoiceNotificationEmail'); } else \nif (window.location.replace){ \nwindow.location.replace('https://evestment--dev.cs13.my.salesforce.com?ec=302&startURL=%2Fapex%2FInvoiceNotificationEmail');\n} else {;\nwindow.location.href ='https://evestment--dev.cs13.my.salesforce.com?ec=302&startURL=%2Fapex%2FInvoiceNotificationEmail';\n} \n</script>\n\n</head>\n\n\n</html>\n\n\n\n\n\n<!-- Body events -->\n<script type=\"text/javascript\">function bodyOnLoad(){if(window.PreferenceBits){window.PreferenceBits.prototype.csrfToken=\"null\";};}function bodyOnBeforeUnload(){}function bodyOnFocus(){}function bodyOnUnload(){}</script>\n\t\t\t\n</body>\n</html>\n\n\n<!--\n...................................................................................................\n...................................................................................................\n...................................................................................................\n...................................................................................................\n-->\n\n\n
The response appears to be a page that is redirecting to a login page, but I could be wrong. I'm making the call to the custom REST endpoint via Postman when I received the undesirable output above. I've tried obtaining a session id via Postman and using the same session id in the call to the REST endpoint AND the call to the Salesforce resource (i.e. replacing UserInfo.getSessionId() with the session id). The user authenticating is a sys admin and is the same user running the anonymous code in the console for the positive test.
Can anyone shed any light on why this might be happening?
HttpRequest request = new HttpRequest(); request.setEndpoint('https://<my hostname>/apex/MyVisualforcePage'); request.setMethod('GET'); request.setHeader('Authorization', 'Bearer ' + UserInfo.getSessionId()); request.setBody('param1=foo¶m2=bar'); HttpResponse response = new Http().send(request); System.debug(response.getBody());... I get the page content in HTML correctly.
However, when I make the same call in a custom REST endpoint I get the following output:
\r\n<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.01 Transitional//EN\" \"http://www.w3.org/TR/html4/loose.dtd\">\n<html>\n<head>\n <meta HTTP-EQUIV=\"PRAGMA\" CONTENT=\"NO-CACHE\">\n\n\n\n\n\n<script>\nif (this.SfdcApp && this.SfdcApp.projectOneNavigator) { SfdcApp.projectOneNavigator.handleRedirect('https://evestment--dev.cs13.my.salesforce.com?ec=302&startURL=%2Fapex%2FInvoiceNotificationEmail'); } else \nif (window.location.replace){ \nwindow.location.replace('https://evestment--dev.cs13.my.salesforce.com?ec=302&startURL=%2Fapex%2FInvoiceNotificationEmail');\n} else {;\nwindow.location.href ='https://evestment--dev.cs13.my.salesforce.com?ec=302&startURL=%2Fapex%2FInvoiceNotificationEmail';\n} \n</script>\n\n</head>\n\n\n</html>\n\n\n\n\n\n<!-- Body events -->\n<script type=\"text/javascript\">function bodyOnLoad(){if(window.PreferenceBits){window.PreferenceBits.prototype.csrfToken=\"null\";};}function bodyOnBeforeUnload(){}function bodyOnFocus(){}function bodyOnUnload(){}</script>\n\t\t\t\n</body>\n</html>\n\n\n<!--\n...................................................................................................\n...................................................................................................\n...................................................................................................\n...................................................................................................\n-->\n\n\n
The response appears to be a page that is redirecting to a login page, but I could be wrong. I'm making the call to the custom REST endpoint via Postman when I received the undesirable output above. I've tried obtaining a session id via Postman and using the same session id in the call to the REST endpoint AND the call to the Salesforce resource (i.e. replacing UserInfo.getSessionId() with the session id). The user authenticating is a sys admin and is the same user running the anonymous code in the console for the positive test.
Can anyone shed any light on why this might be happening?
myccpay (https://www.myccpay.run/)
Hi bobby,
I think you have to use pageReference for Vfpage calling .
First you have to call http request and get response in another org and after that use pageReference and set Param like this.
PageReference pageRef = new PageReference('/apex/myVfPage');
pageRef.setRedirect(true);
pageRef.getParameters().put('param1', foo);
So if you find your Solution then give it Best answer.
Thank you!
Regards,
Suraj Tripathi