1

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 Jan 24 '15 at 0:35
4

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.

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.