If this statement has no records will it return 0 or does the "try" feature cause it to fail and fall thru to the "catch" statement after an if/else statement. The "if" statement checks for the counter to be 1 and then an else for any other number. It seems to fail if there are no matches. The "else" statement never executes Why?

try {Integer counter = [ Select count() FROM E_mail__c Where E_mail_Address__c = :email.fromAddress ];

  • Your code doesn't include any if-else statements, so that part of your question is a bit unclear to me. As for your query, you're actually getting the array[0] results of a list<AggregateResults> query which @Mark Pond seems to have covered why there could be a null pointer exception that a try-catch block could contain. .
    – crmprogdev
    Commented Jan 24, 2015 at 0:35

1 Answer 1


The counter variable will contain 0 if there are no matches found by the query as you've got it written.

If email is null however email.fromAddress will cause a null pointer exception to be thrown and be handled by the respective catch block.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .