-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')];
2
  • 6
    Your question is not clear Commented Feb 15, 2019 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
    Commented Feb 15, 2019 at 13:37

3 Answers 3

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);

1
  • 2
    Apex does not allow newlines in string literals.
    – David Reed
    Commented Feb 15, 2019 at 13:15

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