You need to sign in to do that
Don't have an account?
klocwork
Checking for null value is not returning results
Spinning my wheels on this. I'm not an APEX coder but this problem is within my skill set.
I am trying to check to see if "Account_Record__c" on "Lead" is null - and then insert a record if it is. No errors when I save the code, but when I test none of the records are behaving as expected! In my test records there are no values in "Account_Record__c" yet the related object record is not created. If I remove the "&& newLead.Account_Record__c==null" element then the related record is created.
What am I missing?
trigger createSalesAssignment on Lead (after update) { List<Sales_Assignment__c> sa = new List<Sales_Assignment__c>(); for (Lead newLead: Trigger.New) if (newLead.Status == 'Sales Ready' && newLead.Account_Record__c==null){ sa.add (new Sales_Assignment__c( Lead__c = newLead.Id)); } insert sa; }
when you are && comdition it means
the Account_Record__c should satisfy for both the conditions,
how come it possible if a field is null , it can also have Sales Ready value.
so write your code as follows.
if this answers your question make this as a solution
Thanks for your reply - I think my requirements may have not been clear!
I am looking for records where both conditions are true - where newLead.Account_Record__c==null AND newLead.Status='Sales Ready' because Leads that have an "Account_Record__c" do NOT require a "Sales_Assignment__c" record.
I did test using your code though - and the problem persisted meaning that records with null "Account_Record__c" did not get a "Sales_Assignment__c" record.
Wierd!
Thanks again for your reply - do you have other suggestions?
Hello @klocwork
try this:
if (newLead.Status == 'Sales Ready' &&
(newLead.Account_Record__c==null || newLead.Account_Record__c=='')
)
Regards,
Nash
ok both of them are of different fields,
try with && and also try with ||
and instead of null after == use " "