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
salesforcemicky125salesforcemicky125 

how filter the contacts which have blank email address

I Have a  requirement where i have to filter the Email Address which do not have email address i.e  Email Address is should be blank in the Contact Object.

When i want to send the Email to any one who have Valid email address in the Contact object by clicking on the Go button i will get list of contact records and in that i want to filter the contact reords whose Email Addreess field is Blank so that i can send the email record to the person who have email address field is a having valid email address , but it should not be Blank.

Some one help me out with the Sample Example on how to filter list of records where i don't want to see blank email fields from the list of Contact records have a  valid email adderess . So That i can send the Email to all the contact reords who have email address.

Thank you for responding very quickly,

Actually we are doing it b y custom code , where we will list of contact records with both Email Address and with the Blank email address.

So we don't want to see the Blank email address with the List of Contact  records which have the Valid Email address.



Here is code we have, this is the Method where we will using to get the list of contact records.

I think this may help you more simple what i am looking for


public Pagereference go() {
        errormsg = '';
        errormsg = errorString();
        String conditionstring = '';
        conditionstring = condString();
        String querystring = '';
        string crmcampname;
        crmcampname = opty.CRM_Campaign__C;
        Set<Id> sObjectIds = new Set<Id>();
        System.debug('--->crmcampname' + crmcampname);
        System.debug('--->Conitionstring' + conditionstring);
            List<CRM_Campaign__c> cmp = [Select Id from CRM_Campaign__c where Name =: 'Select Campaign'];
            String cmpid = cmp[0].Id;
           if (crmcampname <> cmpid && conditionstring <> '')
            {
             for(CRM_Campaign_Member__c crm: [Select id,crm_contact__c from CRM_Campaign_Member__c where CRM_Campaign__r.id =: crmcampname])
            {
            sObjectids.add(crm.CRM_Contact__c)  ;
            system.debug('sobjectadd');
            }
            querystring = 'Select AccountId, Email,Name,FirstName, Id, LastName, Title from Contact where id in:sObjectIds';
            querystring = querystring + ' and' + conditionstring + ' LIMIT 1000';//add conditions to the query by appending the conditonString
            System.debug('--->query--First Condition' + conditionstring);
            }
            else
            if ((crmcampname =='cmpid') && (conditionstring <> null && conditionstring <> ''))
            {
                        system.debug('sobjectadd');
            querystring = 'Select AccountId, Email,Name,FirstName, Id, LastName, Title from Contact';
            querystring = querystring + ' Where'+ conditionstring + ' LIMIT 1000';//add conditions to the query by appending the conditonString
            System.debug('--->query--Second Condition' + conditionstring);
            System.debug('--->query' + conditionstring);
            }
            else
            if ((conditionstring <> null && conditionstring == ''))
            {
                        for(CRM_Campaign_Member__c crm: [Select id,crm_contact__c from CRM_Campaign_Member__c where CRM_Campaign__r.id =: crmcampname])
            {
            sObjectids.add(crm.CRM_Contact__c)  ;
            }
              querystring = 'Select AccountId, Email,Name,FirstName, Id, LastName, Title from Contact where id in:sObjectIds';
               System.debug('--->query--Third Condition' + conditionstring);
            }
            else
            querystring = 'Select AccountId, Email,Name,FirstName, Id, LastName, Title from Contact';
          
       if (! (errormsg.contains('Column') || errormsg.contains('Operator')))
         {
            System.debug('The querystring is' + querystring);
            System.debug('crmcampname' + crmcampname);
            filerResult = Database.query(querystring);//execute the query
            sscResults = new ApexPages.StandardSetController(filerResult);
            sscResults.setPageSize(25);//set the page size for pagination
        }
         else
          {
            ApexPages.Message myMsg = new ApexPages.Message(ApexPages.Severity.FATAL, errormsg);
            ApexPages.addMessage(myMsg);
        }
           return null;
    }

Regards
Micky
CyberJusCyberJus
Based on the code you posted just change 

String conditionstring = ''; 
to
String conditionstring = ' Email <> \'\' ';