1

I am trying to compute a query from a string variable such as

 public String query = 'SELECT Id,ownerid,closedate,name FROM Opportunity WHERE isClosed =false and closedate =: dtreshold  and (stagename != "Pending Payment" OR stagename != "Complete"  OR stagename !=    "Rejected"   OR stagename !=    "Cancelled"  )';

But upon executing it it gives me the following error:

10:50:26:019 EXCEPTION_THROWN [17]|System.QueryException: line 1:124 no viable alternative at character '"'

1
  • 1
    did you try to use the single quote with backslash at stagename checking?
    – Subhash
    Commented Jun 16, 2016 at 9:55

1 Answer 1

3

no viable alternative at character '"' usually means that you have used double quotes " instead of single quotes '.

To solve this, you should replace your double quotes with single quotes and escape them with a backslash. Try this:

 public String query = 'SELECT Id,ownerid,closedate,name FROM Opportunity WHERE isClosed =false and closedate =: dtreshold  and (stagename != \'Pending Payment\' OR stagename != \'Complete\'  OR stagename !=    \'Rejected\'   OR stagename !=    \'Cancelled\'  )';

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .