I need the send PUT request to my SalesforceMiddleware project using with javascript button, with that situation i used the resource below:

sforce.connection.remoteFunction https://resources.docs.salesforce.com/sfdc/pdf/apex_ajax.pdf

can anyone help me ?


var productCode = '{!Product2.ProductCode}';

if (productCode != '') {
    url : "{DELETED}/"+productCode,
    requestHeaders: {"Content-Type":"application/json"},
    method: "PUT",
    requestData: productCode,
    onSuccess : function (result){console.log('success')},
    onFailure : function (error) {console.log('error')},
} else {
    alert('Select one or more Contacts');

Edit: by the way i getting HTTP 400 Bad Request message

Console log

1 Answer 1


I could not get any answer to my question that's why i found another way. It's some challenging, but working.

I'm sharing my HttpRequestPostOrPut apex class:

global class HttpRequestPostOrPut {
webservice static string request(string url, string method, string contentType)
    Http http = new Http();
    HttpRequest request = new HttpRequest();
    request.setHeader('Authorization', 'OAuth ' + UserInfo.getSessionId());
    request.setHeader('Content-Type', contentType);
    HttpResponse response = http.send(request);
    if(response.getStatusCode() == 200) {
        return response.getBody();
    return null;

And mockTestClass

global class HttpRequestPostOrPutMock implements HttpCalloutMock {
    global HTTPResponse respond(HTTPRequest req) 
            HttpResponse res = new HttpResponse();
            res.setHeader('Content-Type', 'application/json');
            return res; 
    public static void HttpRequestPostOrPutTest() 
    Test.setMock(HttpCalloutMock.class, new HttpRequestPostOrPutMock());
    HttpRequestPostOrPut.request('{DELETED}/{sku}', 'PUT', 'application/json');

And js button execute command


requestUrl = "{Deleted}/{!Product2.ProductCode}";

var result = sforce.apex.execute("HttpRequestPostOrPut","request",{url: requestUrl, method:"PUT", contentType: "application/json"});


I hope I can help someone with this.

You must log in to answer this question.

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