1

I'm sending some data into SalesForce but am having some issues with some values that are destined for a multiple select. I don't beleive this is specific to Salesforce so I'm posting the question here.

This is my current script:

<?php

  if($_POST['cis'] == '1'){
    $query['00ND0000003viLy'] = array(
      'Essential',
      'CIS'
    );
  }else{
     $query['00ND0000003viLy'] = 'Essential';
  }

  foreach ( $query as $key => $value) {
    $post_items[] = $key . '=' . $value;
  }
  $post_string = implode ('&', $post_items);

  $curl = curl_init();
  curl_setopt($curl, CURLOPT_URL, 'xxx');
  curl_setopt($curl, CURLOPT_POST, count($post_items));
  curl_setopt($curl, CURLOPT_POSTFIELDS, $post_string);
  curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, FALSE);
  curl_setopt($curl, CURLOPT_RETURNTRANSFER, TRUE);
  curl_setopt($curl, CURLOPT_FOLLOWLOCATION, TRUE);

  $result = curl_exec($curl);

  curl_close($curl);

  echo $result;

?>

At SalesForces' end the value for $query['00ND0000003viLy'] ends up coming in as a string, Array (when it matches the condition).

How do I assign multiple values to $query['00ND0000003viLy'] so that it can be interpreted as though it were a multiple select?

Nathan Hornby
  • 1,423
  • 16
  • 32
  • Check out this question for some options. http://stackoverflow.com/questions/3772096/posting-multidimensional-array-with-php-and-curl – sanderbee Sep 11 '15 at 11:22
  • Hm, I've just taken a look, but I'm not sure how it relates really. I'm not experiencing any errors, I just need to know how to form a multiple select for this kind of curl execution. – Nathan Hornby Sep 11 '15 at 11:24

2 Answers2

1

Ok so it turns out this may well be something salesforce specific, the tl;dr is that the values need to be a single string and seperated with a semi-colon. So this is the working code given my example:

if($_POST['cis'] == '1'){
    $query['00ND0000003viLy'] = 'Essential; CIS';
  }else{
     $query['00ND0000003viLy'] = 'Essential';
  }

For others that need a more dynamic solution then something along these lines should do it:

join(';', $query['00ND0000003viLy'])

(again, given my original example).

Crux of answer tracked down here: https://developer.salesforce.com/forums/?id=906F00000008ssBIAQ

Oh and @sanderbee 's answer contains a much neater way to build the query.

Nathan Hornby
  • 1,423
  • 16
  • 32
0

Add the parameters as a http query string like this:

$post_string = http_build_query($query);

curl_setopt($curl, CURLOPT_URL, 'xxx');
curl_setopt($curl, CURLOPT_POST, true);
curl_setopt($curl, CURLOPT_POSTFIELDS, $post_string);
curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, FALSE);
curl_setopt($curl, CURLOPT_RETURNTRANSFER, TRUE);
curl_setopt($curl, CURLOPT_FOLLOWLOCATION, TRUE);
sanderbee
  • 694
  • 7
  • 24
  • Just gave this a shot, all the other fields (omitted from the question) made their way in fine, but this field is now blank, so not even the string `Array`. – Nathan Hornby Sep 11 '15 at 12:03
  • Regardless that's clearly a neater way to handle building the query! – Nathan Hornby Sep 11 '15 at 12:11
  • 1
    Hmm, thats strange. Just tried it with your data and it works fine for me. I only changed the CURL_POST value to true... – sanderbee Sep 11 '15 at 12:18
  • Ah sorry I hadn't even noticed the change there, I'll give that a try! – Nathan Hornby Sep 11 '15 at 12:47
  • Even after that change it's still coming through blank for that field. Looking at the Salesforce provided web-to-lead form for this action all it's doing is treating the field as a multiple select, I can't see anything unique about it. But maybe it is something salesforce specific… – Nathan Hornby Sep 11 '15 at 12:50
  • Ah I got it, it _is_ something salesforce specific - although I have no idea how their provided forms would ever work without something to reformat these fields. The values just need to be seperated with a semi-colon. – Nathan Hornby Sep 11 '15 at 13:03