function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
shmessihashmessiha 

A problem while using Salesforce API

Hello,

 

I need your help to fix a problem that i have with my application using salesforce API,

 

I'm using PHP development invironment. 

 

I'm used to send XML request to create/update salesforce objects [leads, contacts or activity history].

And to send the XML request, i have to escape the XML special characters so i can send a valid XML request.

Special characters are like:

  • '&' (ampersand) becomes '&'
  • '"' (double quote) becomes '"' when ENT_NOQUOTES is not set.
  • ''' (single quote) becomes ''' only when ENT_QUOTES is set.
  • '<' (less than) becomes '&lt;'
  • '>' (greater than) becomes '&gt;'

Note: if i didn't escape these special characters then the request will fail.

 

The problem is that these special characters aren't mapped back on the server to thier equivalent, i mean if want to set the description of a lead into:

this is a customer description for a lead with these special & " ' < > characters.

Then what i find on Salesforce is:

 this is a customer description for a lead with these special &amp; &quot; &#039; &lt; &gt; characters.

Which doesn't make sense.

Please i need your help on how to fix this issue.

 

Thanks in advance

 

eng.imad.atia@gmail.com 

 
SuperfellSuperfell
It would appear they're getting double encoded. are you using the php toolkit for salesforce? that'll likely already handle the xml encoding issues.
msimondsmsimonds

if you are using PHP and using an array to update your code, I would use htmlspecialchars on the fields which will convert the values to XML. An example would be if you had an update array called $row you could use:

 

 

$row = array_map('stripslashes',$row)

 

 

 

 

 I would also trim your input data:

 

 

$row = array_map('trim',array_map('stripslashes',$row));

 

 

Hope that helps

 

~Mike

 

 

 

 

SergiSergi
I think you should use CDATA sections when text contains that special chars.
victoravalosvictoravalos

How were you able to get around this?  

 

Stripslashes has not worked for me and I wondered if you ended up using CDATA.  

 

If you have a sample that you can share using the PHP tookit, I would be very appreciative.

 

I have My Topic here if you prefer to respond there.

victoravalosvictoravalos

If you have a sample that you can share using the PHP tookit, I would be very appreciative.

 

I have My Topic here if you prefer to respond there.