List<Opportunity> opps = [
SELECT Id
,Name
,Amount
,CloseDate
,Stagename
,Near_to_Close_Date__c
FROM Opportunity
WHERE Stagename Not In ('Closed Lost', 'Closed Won')];
-
6Your question is not clear– Santanu BoralFeb 15, 2019 at 9:58
-
1This 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, 2019 at 13:37
3 Answers
I see you're new there, you can use the official documentation there ;
This may be what you're looking for ?
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.
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