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
ekbekb 

Malformed Query

Hello

 

I am building an interface to salesforce to extract some data. I am trying to query the data that has been modified in the last 2 days. I formulated the query as below, but I am getting a MALFORMED_QUERY error. Initially i enclosed the data in quotes, but i got an explict error not to use quotes, any idea ?

 

 

select column1, column2  from sobject_name where lastModifiedDate >=2009-07-27T08:00:00.000

 

 

LastModifiedDate >=2009-07-27T08:00:00
^
ERROR at Row:1:Column:123
line 1:123 no viable alternative at character '<EOF>'
Best Answer chosen by Admin (Salesforce Developers) 
SteveBowerSteveBower

There are some built-in helpers for date queries.  Check the Query Language doc. 

 

Extract:

 

LAST_N_DAYS:nFor the number n provided, starts 12:00:00 of the current day and continues for the last n days.SELECT Id FROM Account WHERE CreatedDate = LAST_N_DAYS:365

 

Best, Steve.

All Answers

SteveBowerSteveBower

There are some built-in helpers for date queries.  Check the Query Language doc. 

 

Extract:

 

LAST_N_DAYS:nFor the number n provided, starts 12:00:00 of the current day and continues for the last n days.SELECT Id FROM Account WHERE CreatedDate = LAST_N_DAYS:365

 

Best, Steve.

This was selected as the best answer
ekbekb

Nice suggestion. I found the issue with the original syntax, had to include a Z at the end

 

select...where lastmodifieddate >= 2009-07-27T08:00:00Z

Ranjeet GholaveRanjeet Gholave

SELECT Id,FirstName,LastName from Contact WHERE Email="aancsjjsjadjkadha'sdweiunjncjxzncnzjjhdsadsas11@gmail.com"

 

I Am retriving the result from salesforce then i get the this  error

 

no viable alternative at character '"' in D:\wamp\www

 

And my $forceBaseClient.php

file  this is function.

public function query($query) {  
        $this->setHeaders("query");
        $raw = $this->sforce->query(array (
                      'queryString' => $query
        ))->result;
        $QueryResult = new QueryResult($raw);
        $QueryResult->setSf($this); // Dependency Injection
        return $QueryResult;
    }

 

When I Try To retrieve Email for eq.   ranjeet's1189@gmail.com Query Fails

Thank you

Zeus0529Zeus0529

I have a similar error, but for a different reason. When you specify an email address it needs to be surrounded as a literal (surrounded by single quotes). You cannot have a single quote as part of an email address. Hope that helps.