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
CaptaConsultingCaptaConsulting 

Soql query error with the AJAX Toolkit

Hi,

When I execute my AJAX code:

........

_qrLeads = sforceClient.Query("Select Id, LastName, FirstName, State, Email , CreatedDate, LastModifiedDate, OwnerId From Lead where CreatedDate >= 2005-01-01 and CreatedDate
alert("_qrLeads: "+_qrLeads)

........

I get this error:

_qrLeads: faultstring: org.xml.sax.SAXParseException: The content of elements must consist of well-formed character data or markup.
faultcode: soapenv:Server
SOQL: Select Id, LastName, FirstName, State, Email , CreatedDate, LastModifiedDate, OwnerId From Lead where CreatedDate >= 2005-01-01 and CreatedDate

If I executed this query in the sforce Explorer works perfect.

Thanks.
DevAngelDevAngel

Hi CaptaConsulting,

Sounds like this might be a date only field serialization problem.  I'll check it out.

DevAngelDevAngel
Hi CaptaConsulting, The problem is that the AJAX toolkit is not encoding the special characters properly. Until there is a patch, you add the following to your page init function. SforceClient.prototype.Query2 = function(soql, xhandler) { soql = soql.replace(//g, ">"); return sforceClient.Query(soql, xhandler); };
DevAngelDevAngel

To follow up, (it was hard to get the code to display well) you would then use sforceClient.Query2(soql, handler) to run your query.  This will properly encode the less than and greater than symbols in the soql statement to result in well formed xml for the soap message.

 

Thanks for the catch.

spikeJonzespikeJonze
**bleep** straight it doesn't display well, just took me an hour to figure out what you were suggesting! This forum needs a raw text option for inserting html and other source code. Make our lives a lot easier!

aj
CaptaConsultingCaptaConsulting
Hi spikeJonze,

I don´t know what are the code inside de "replace" call....

soql.replace(¿HERE which is the code?, ">");




Thanks.


Victor Alvarez
Capta Consulting
DevAngelDevAngel
That's a regular expression. The idea is to replace the less than and greater than with < and >.
CaptaConsultingCaptaConsulting
This works right

Thanks Dave.


Victor Alvarez
Capta Consulting