4

I have a simple query in my JavaScript within a VisualForce page. and it is giving me MALFormed Query exception, unexpected token: annualVolume. Here is the code:

function queryPricingModel()
{
    try
    {
        var myQuery = sforce.connection.query("SELECT BP__c FROM PC_BP_Matrix__c WHERE StartVolume__c < annualVolume");
        pcBP = myQuery;
    }
    catch(error)
    {
        alert(error.faultstring);
    }
}

Please Help, thanks

6

Where do you assign value to annualVolume variable? If it's a JS variable in the global scope, you cannot simply pass a JS varible to the query by placing it in the query string. What you should do is create a query string with value of the annualVolume variable.

E.g.

function queryPricingModel()
{
    try
    {
        var myQuery = "SELECT BP__c FROM PC_BP_Matrix__c WHERE StartVolume__c < " + annualVolume;
        pcBP = sforce.connection.query(myQuery);
    }
    catch(error)
    {
        alert(error.faultstring);
    }
}


As a proof of concept, you can try to replace annualVolume variable with a literal value in your initial example.

  • annualVolume is a global variable which will be assigned a value when the user enters the number on the page. – user3088377 Jan 16 '14 at 15:24
  • As I assumed. In that case, try the example I've given you. You cannot place a JS variable in a string literal (between quotation marks) and expect it to resolve properly. What you have done is simply written a string containing "annualVolume" characters. – dino ursic Jan 16 '14 at 15:27
  • I see what you are saying now. I was pass the word "annualVolume" in the query string instead of its value. thank you so much. – user3088377 Jan 16 '14 at 15:28
  • No problem, glad I could help ;) – dino ursic Jan 16 '14 at 15:28

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.