0

I have around 12 fields. Trying to write a SOQL query for more than one field to exclude null values.

For single field which is not null, I am able to get the records. I want to a SOQL to get the records for all 12 fields which are not null.

Below is the SOQL to get the records for single field which is not null:

SELECT Name ,AccountNumber, OwnerId,ParentId, Data_Center_BDE__c,Tele_CDE__c,DMS_Owner__c,Primary_Local_Market_Rep_1__c,Information_Governance_Rep__c,DM_Cloud_Sales_Rep__c,Primary_BDE__c,Primary_CDE__c,Primary_BDE_DB_R__c,Primary_CDE_DB_R__c,Library_Services_BDE__c FROM Account WHERE Data_Center_BDE__c != NULL

similarly I want to write for other 12 fields which are not null. Can you please suggest.

1

You should just be able to use AND

SELECT Name ,AccountNumber, OwnerId,ParentId, Data_Center_BDE__c,Tele_CDE__c,DMS_Owner__c,Primary_Local_Market_Rep_1__c,Information_Governance_Rep__c,DM_Cloud_Sales_Rep__c,Primary_BDE__c,Primary_CDE__c,Primary_BDE_DB_R__c,Primary_CDE_DB_R__c,Library_Services_BDE__c FROM Account WHERE Data_Center_BDE__c != NULL AND OtherField != NULL

The above would be for 2 fields. Add as many more as you need.

0

Below query is working for my question.

SELECT Name ,AccountNumber, OwnerId,ParentId, Data_Center_BDE__c,Tele_CDE__c,DMS_Owner__c,Primary_Local_Market_Rep_1__c,Information_Governance_Rep__c,DM_Cloud_Sales_Rep__c,Primary_BDE__c,Primary_CDE__c,Primary_BDE_DB_R__c,Primary_CDE_DB_R__c,Library_Services_BDE__c FROM Account where Data_Center_BDE__c != NULL and Tele_CDE__c != NULL and DMS_Owner__c != NULL and Primary_Local_Market_Rep_1__c != NULL and Information_Governance_Rep__c != NULL and DM_Cloud_Sales_Rep__c != NULL and Primary_BDE__c != NULL and Primary_CDE__c != NULL and Primary_BDE_DB_R__c != NULL and Primary_CDE_DB_R__c != NULL and Library_Services_BDE__c != NULL

1
  • Glad you managed to get your answer. Would appreciate it if you marked mine as accepted if it helped :)
    – Dave
    Mar 10 at 17:56

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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