-4

I am trying to display a records which not having status like Approved and Rejected. as of now i am checking for only one status.

Here is my Query:

string strQuery = 'select Id,ContentDocumentId,DocumentCommunication__r.Name,DocumentCommunication__r.id,DocumentCommunication__r.Document_Status__c,DocumentCommunication__r.ParentObjectId__c,DocumentCommunication__r.Type__c from ContentVersion where DocumentCommunication__r.Document_Status__c ='+'\'Pending Review\'';
3

This is very easy and simple. If you want to exclude any value we use NOT IN if they are multiple or != will also work.

So in your case first create set with all values which you want to exclude

set<string> appstatus = new set<string>();
appstatus.add('Approved');
appstatus.add('Rejected');

then in your dynamic query

' ... where DocumentCommunication__r.Document_Status__c NOT IN: appstatus';

Also as this is a simple query so you can use static query as well

[ ... where DocumentCommunication__r.Document_Status__c NOT IN: appstatus];

From @DerekF Comments :

About the only caveat here is that using NOT IN or != will cause the filter (something of the form field value) to not count towards making your query "selective". Query selectivity is probably not something that you need to worry about right now, but it is something to keep in mind. Generally speaking, I prefer using "positive" filters (those that use =, IN, <, >, etc...) over negative filters (!=, <>, NOT IN).

  • 2
    For @Elango: About the only caveat here is that using NOT IN or != will cause the filter (something of the form field <operator> value) to not count towards making your query "selective". Query selectivity is probably not something that you need to worry about right now, but it is something to keep in mind. Generally speaking, I prefer using "positive" filters (those that use =, IN, <, >, etc...) over negative filters (!=, <>, NOT IN). – Derek F Oct 10 '17 at 12:50
-3
string strQuery = 'select Id,ContentDocumentId,DocumentCommunication__r.Name,DocumentCommunication__r.id,DocumentCommunication__r.Document_Status__c,DocumentCommunication__r.ParentObjectId__c,DocumentCommunication__r.Type__c from ContentVersion where DocumentCommunication__r.Document_Status__c!= 'Pending' and DocumentCommunication__r.Document_Status__c!= 'Review'
  • 4
    While this is (mostly) correct (you'd need to escape the single quotes surrounding 'Pending' and 'Review'), I'm downvoting this answer because it is what we call a "code dump". Good answers will explain (using words) what the OP's (Original Poster of the question) problem was, provide a solution, and then explain how the solution addresses the issue(s) in the question. Without proper explanation, answers tend to gather comments like "this doesn't work" and "try <new code here> instead", which doesn't help OP learn how to avoid similar issues in the future. – Derek F Oct 10 '17 at 12:37

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