function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
jOseMCjOseMC 

how to mention more than one field after a where and informally that they are different from null?

how to mention more than one field after a where and informally that they are different from null?  in my developer console I wrote as follows
ServiceContract scQuery = [SELECT BankId__c, Agencia__c, Conta__c, CNPJ__c, Digito_Conta__c,Tipo_de_Conta_Bancaria__c, Conta_Poupanca__c
                                   from ServiceContract where BankId__c != null, Agencia__c != null, Conta__c != null,CNPJ__c != null, Digito_Conta__c != null,Tipo_de_Conta_Bancaria__c != null  ];
        System.assert(scQuery != null , 'Bank account should be equals from Service Contract');
but the following errors are showing​​​​​​​

User-added image
Best Answer chosen by jOseMC
AnkaiahAnkaiah (Salesforce Developers) 
Hi,

try with below code.

If you want to check all the fields conditions != Null then use AND
ServiceContract scQuery = [SELECT BankId__c, Agencia__c, Conta__c, CNPJ__c, Digito_Conta__c,Tipo_de_Conta_Bancaria__c, Conta_Poupanca__c from ServiceContract where (BankId__c != null AND Agencia__c != null AND Conta__c != null AND CNPJ__c != null AND Digito_Conta__c != null AND Tipo_de_Conta_Bancaria__c != null) ];
System.assert(scQuery.size()>0, 'Bank account should be equals from Service Contract');
If you want to check any one of  the field conditions != Null then use OR
 
ServiceContract scQuery = [SELECT BankId__c, Agencia__c, Conta__c, CNPJ__c, Digito_Conta__c,Tipo_de_Conta_Bancaria__c, Conta_Poupanca__c from ServiceContract where (BankId__c != null OR Agencia__c != null OR Conta__c != null OR CNPJ__c != null OR Digito_Conta__c != null OR Tipo_de_Conta_Bancaria__c != null )];
System.assert(scQuery.size()>0, 'Bank account should be equals from Service Contract');

If this helps, Please mark it as best answer.

Thanks!!