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?

2
  • Check out this question for some options. stackoverflow.com/questions/3772096/… Commented Sep 11, 2015 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. Commented Sep 11, 2015 at 11:24

2 Answers 2

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.

Sign up to request clarification or add additional context in comments.

Comments

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);

6 Comments

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.
Regardless that's clearly a neater way to handle building the query!
Hmm, thats strange. Just tried it with your data and it works fine for me. I only changed the CURL_POST value to true...
Ah sorry I hadn't even noticed the change there, I'll give that a try!
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…
|

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.