salesforce-python-client / pyforce

A fork of the salesforce beatbox client.
GNU General Public License v2.0
26 stars 24 forks source link

sendEmail doesn't support multiple toAddresses #14

Open ellieayla opened 9 years ago

ellieayla commented 9 years ago

http://www.salesforce.com/developer/docs/api/Content/sforce_api_calls_sendemail.htm states that several fields, including toAddresses, accept arrays of values. in SOAP XML, this translates to multiple <p:toAddresses /> elements.

In pyforce.py _doPrep, there exists a joining of list items, which results in multiple items concatenated in a single element instead of multiple elements.

      else:
            field_dict[k] = ";".join(v)
ellieayla commented 9 years ago

If this was a no-op or as follows, the generated SOAP XML request would have multiple <p:toAddresses /> elements.

     else:
            field_dict[k] = v

However, I do not know whether that would break anything else. Presumably this implementation is as-is for a reason. Maybe _prepareSObjects should be special-cased for sendEmail.

idbentley commented 9 years ago

Yes, at least in some cases the sfdc api correctly parses ; delimited strings into arrays of strings. I haven't tested it with emails, and I assume you are bringing this forward because you have tested it?

I can't find the documentation about string array parsing, but I find it odd that it would be inconsistent. Can you try and find the related doucmentation?

ellieayla commented 9 years ago

Yes, I have tested it with with a list like ToAddresses = ["me@example.com", "you@example.com"], and with that one-line hack above. A modification to the post function to dump xml payload makes the mismatch apparent.

ellieayla commented 9 years ago

It seems like this semicolon behavior is specific to multi-value picklist fields. http://www.salesforce.com/developer/docs/api/Content/field_types.htm#i1435691 says

Multi-select picklist fields contain a list of one or more items from which a user can choose multiple items. One of the items can be configured as the default item. Selections are maintained as a string containing a series of attributes delimited by semicolons. For example, a query might return the values of a multivalue picklist as “first value; second value; third value”. For information on querying multi-select picklists, see Querying Multi-Select Picklists in the Salesforce SOQL and SOSL Reference Guide.

See also;

  1. https://success.salesforce.com/answers?id=90630000000giKLAAY
  2. http://salesforce.stackexchange.com/questions/10887/pulling-picklist-options-from-a-multi-value-field
  3. http://www.salesforce.com/us/developer/docs/officetoolkit/Content/sforce_api_calls_soql_querying_multiselect_picklists.htm
ellieayla commented 9 years ago

This behavior mirrors multiMarshaller in marshal.py. Looks like it's been around for a while.

ellieayla commented 9 years ago

Note that this only affects pyforce.Client. xmlclient.Client doesn't do any marshaling of outbound lists so the list of addresses goes through intact.

idbentley commented 9 years ago

This is a little bit annoying, and requires handling ; as a special case.

ellieayla commented 9 years ago

I deferred the decision for how that special handling should be done and just documented the problem. If you feel strongly about a particular solution please propose it.