+ Start a Discussion
Waqar Hussain SFWaqar Hussain SF 

how to use not contain condition in apex?

IF (object.Field__c.contains( 'string' ) ?
 IF (object.Field__c. NOT contains( 'string' ) ?
do {
Best Answer chosen by Waqar Hussain SF
James LoghryJames Loghry

The contains method returns a boolean, so you can use boolean operators on the result.

Some of the various operators include:
&& (And)
|| (Or)
|= (Assigns the result of the OR condition back to the variable in front of it)
&= (Assigns the result of the AND conditon back to the variable in front of it)

Finally the one that you need is:

! (Not some condition)

In other words change your IF statement to the following:


You may need to check for null conditions on object / Field__c as well. You may also want to use containsIgnoreCase instead of "contains" if you want a case-insensitive check.