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
    did you try to use the single quote with backslash at stagename checking? – Subhash Jun 16 '16 at 9:55
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\'  )';
| improve this answer | |

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.