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
Stefanos.ThomaidisStefanos.Thomaidis 

Clone in an SQL Statement gives error

The following code worked last week!

It clones the first record of a related object.  I keep it on a button.

Has anything chenged in Salesforce over the weekend?

The code:

{!REQUIRESCRIPT("/soap/ajax/21.0/connection.js")}
{!REQUIRESCRIPT("/soap/ajax/21.0/apex.js")}

var a = {!Location__c.Name}

var result  = sforce.connection.query("SELECT SessionIDs__c FROM Promo_Material_Snapshot__c"+  
" WHERE Location_ID__c = '"+ a +"'  limit 1")

// var result  = sforce.connection.query("SELECT SessionIDs__c FROM Promo_Material_Snapshot__c limit 1")

var records = result.getArray("records")
var IdsToClone = String(records[0]).substring(60, 75)
window.open("/"+IdsToClone +"/e?clone=1&retURL=/"+IdsToClone )

 

Now it gives the following error:

 

faultcode: MALFOREMED QUERY..

...

no viable alternative at character...

 

Last Week it Worked Fine!

 

Any ideas / Suggestions?

All the best,

Stefanos

SabrentSabrent

Not too sure if this will work but try putting your SOQL in single quotes intead of double and also where you have the single quotes in the Where clause escape the single quotes with a forward slash.

 

eg:

 

var result  = sforce.connection.query('SELECT SessionIDs__c FROM Promo_Material_Snapshot__c "+  
" WHERE Location_ID__c = \'"+ a +"\'  limit 1')