-4
List<Opportunity> opps = [
        SELECT  Id
                ,Name
                ,Amount
                ,CloseDate
                ,Stagename
                ,Near_to_Close_Date__c
        FROM    Opportunity
        WHERE Stagename Not In ('Closed Lost', 'Closed Won')];
  • 6
    Your question is not clear – Santanu Boral Feb 15 '19 at 9:58
  • 1
    This query does not need to be dynamic, and most likely shouldn't be. If you have a specific objective for using Dynamic SOQL, you should edit your question to clarify that. – David Reed Feb 15 '19 at 13:37
3

I see you're new there, you can use the official documentation there ;

This may be what you're looking for ?

enter image description here

2

You can use below equivalent dynamic soql.

List<Opportunity> opps = Database.query( 'SELECT Id,Name,Amount,CloseDate,Stagename,Near_to_Close_Date__c '+
                               +'FROM Opportunity '+
                               +'WHERE Stagename Not In (\'Closed Lost\', \'Closed Won\')');

More on Dynamic soql.

-1

You can use this link

OR

String queryString = 'SELECT Id,Name,Amount,CloseDate,Stagename,Near_to_Close_Date__c FROM Opportunity WHERE Stagename Not In (\'Closed Lost\', \'Closed Won\')'; List<Opportunity> opps = Database.query(queryString);

  • 2
    Apex does not allow newlines in string literals. – David Reed Feb 15 '19 at 13:15

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