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
test codetest code 

Where condition not filtering data as expected.

Hi I am new to salesforce. my code is not giving any error but the where condition in query is not filtering data when I am adding second 'OR' clause in it. If I am not adding second OR clause the code is working in the expected way but moment I am adding any OR clause the query is not filtering any record it is just returning entire data.

 

trigger CloseLead2NEW on Contact (before update, before insert) {


List<Lead> lee=new List<Lead>();

Lead leeList;

Contact cc;

List<Lead> Updatelee=new List<Lead>();

if (Trigger.isUpdate||Trigger.isInsert)

{

    cc=Trigger.New[0];
  
 lee=[select id,TEB_ID__c,Citizenship_Number__c,Tax_Number__c from Lead where TEB_ID__c=:cc.TEB_ID__c OR Citizenship_Number__c=:cc.Citizenship_Number__c OR Tax_Number__c=:cc.Tax_Number__c ];
 if(lee.size()>0)
 {

        for(Lead l:lee)
        {
        l.Test_Integer_Field__c=lee.size();

                            l.Status='Closed';
                 
                             leeList= new Lead(id=l.id,Status=l.Status);
            Updatelee.add(leeList);
          
  
}
}
}
 

update Updatelee;

 

}

 

Please hlep and Thanks.

 

SamuelDeRyckeSamuelDeRycke

I'm not sure why the filtering isn't working, but:

 

cc=Trigger.New[0]; --> this is not a good idea, if your trigger is ever used to process a bulk of contacts, it won't work. Have a look at this article : http://wiki.developerforce.com/page/Best_Practice:_Bulkify_Your_Code

 

Using a code block will enhance code readability !:)

 


carlocarlo

I think I had a lot of data returned when one of my filter values was null.  If you have a lot of data with null in field1 and you say where field1 = :cc.field1 when in fact cc.field is null.