0

My client has a Web-to-Lead form on their WordPress site that collects info and sends the data to Salesforce. Salesforce then creates a new record within a custom object.

What I want to do is create another form (not Web-to-Lead) that updates an existing record.

Is there a way that I can update an existing record via the Force.com REST API? Should I even be using it? I'm a WordPress developer, not a Salesforce developer, so I have little-to-no knowledge in this space.

I followed this tutorial and created a Connected App in a Sandbox (I don't want to accidentally update or delete real-world records). The Connected App's callback URL is to my local MAMP server that has a fake SSL script. I then supplied the tutorial code with my client ID and secret, logged into my Salesforce Sandbox at test.salesforce.com, clicked "Allow," and I got this error:

Error: call to token URL https://test.salesforce.com/services/oauth2/token failed with status 400, response

It also says that the connection isn't secure enough:

Stronger security is required. To access this website, update your web browser or upgrade your operating system to support TLS 1.1 or TLS 1.2.

I went to this website that checks if TSL 1.0 is deactivated, and it told me it is.

Right now I'm just trying to get the API working correctly -- not even worrying about updating any records -- so I am calling this function within the demo_rest.php file. What it's supposed to do is return all the Ids of all of the records within the Enquiry custom object.

function show_enquiries_by_id($instance_url, $access_token) {
    $query = "SELECT Id from Enquiry__c";
    $url = "$instance_url/services/data/v20.0/query?q=" . urlencode($query);

    $curl = curl_init($url);
    curl_setopt($curl, CURLOPT_HEADER, false);
    curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
    curl_setopt($curl, CURLOPT_HTTPHEADER,
            array("Authorization: OAuth $access_token"));

    $json_response = curl_exec($curl);
    curl_close($curl);

    $response = json_decode($json_response, true);

    $total_size = $response['totalSize'];

    echo "$total_size record(s) returned<br/><br/>";
    foreach ((array) $response['records'] as $record) {
        echo $record['Id'] . ", " . $record['Name'] . "<br/>";
    }
    echo "<br/>";
}

The Connected App has the following permission: Access and manage your data

Web browser: Chrome 59.0.3071.115

OS: OSX Yosemite 10.10.5

3

Is there a way that I can update an existing record via the Force.com REST API? Should I even be using it? I'm a WordPress developer, not a Salesforce developer, so I have little-to-no knowledge in this space.

The REST API is well-documented, so as long as you're familiar with JSON in the language of your choice (PHP), you should be okay. There's nothing terribly magical about Saleforce's REST API.

I followed this tutorial and created a Connected App in a Sandbox (I don't want to accidentally update or delete real-world records).

The Connected App can exist in any org, even your production org. The Connected App is used to differentiate your app from any other app in the world. What really matters is what URL you're logging in to. As long as your server is directing to https://test.salesforce.com/, you won't be affecting production data.

It also says that the connection isn't secure enough:

You'll need to set the appropriate TLS version:

curl_setopt($curl, CURLOPT_SSLVERSION, CURL_SSLVERSION_TLSv1_2);

You need to do this for the token call, which is where your error is occurring, as well as anywhere else you want to call Salesforce.

Web browser: Chrome 59.0.3071.115

OS: OSX Yosemite 10.10.5

The OS and browser don't matter here, but instead the PHP's version is what matters here. As long as you're using a recent version, you should be okay.

  • Thanks for the help, @sfdcfox! The TLS error is gone, but I got a new error: Error: call to token URL https://test.salesforce.com/services/oauth2/token failed with status 0, response , curl_error Unsupported SSL protocol version, curl_errno 35. I'm sure I can resolve that by updating to the latest version of MAMP. My PHP version is 7.0, by the way – Matthew Jul 23 '17 at 2:24
  • @Matthew You can also try v1_1 instead; you just need to be higher than TLS 1.0. Updating MAMP should also work. – sfdcfox Jul 23 '17 at 4:49

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.