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

Redirect after an HttpRequest POST?

In a Visualforce controller, if I need to do an HTTP POST to an external website and then redirect to that same URL, how do I do it?

Here's the situation: currently the client has a plain HTML form (standard HTML form and input tags) that submits search criteria fields directly to a 3rd party search web site. This appears in a new window and displays a list of results.

They want a custom button on the Salesforce account detail page to submit account fields as search criteria to the external website. It should still open a new window to show the results

Question is: once I send the HTTPRequest in the controller, how do I redirect to the external website? Do I set up a PageReference to the HttpResponse, or just to the original URL?
Rajiv Penagonda 12Rajiv Penagonda 12
dmcheng, I think you don't have to worry about controller or other server side coding. You can achieve the feature you mentioned through a javascript button on your account detail page, reference code below:

var acc_obj = sforce.connection.query("SELECT id, Name FROM Account WHERE id='{!Account.Id}'");
var external_url = "<EXTERNAL_WEBSITE_HERE>/id=" + + "&name=" + acc_obj.Name;, 'targetWindow', 'toolbar=no,location=no,status=no,menubar=no,scrollbars=yes,resizable=yes,width=<SIZE_HERE>,height=<SIZE_HERE>');

I have assumed that the external website accepts url parameters link SFDC dees. You'd have to change that to appropriate format which the external site expects.

Hope this helps.
Thanks for your reply.  Unfortunately I was just informed that the client will be enabling Lightning, so I won't be able to use a Javascript button.

However I talked to a colleague and he suggested building a Visualforce page with an apex:form tag, set the input fields to the account merge fields, and use Javascript to submit the form to the external website, so I will try that.