You need to sign in to do that
Don't have an account?
![plarsen plarsen](https://dfc-org-production.my.site.com/img/userprofile/default_profile_45_v2.png)
Can't catch exception!!
Hi,
Im working with a dynamic where-statement in a query, and I want to be able to catch errors like when a user is entering a non-existing field name:
String Query1 = 'select count() from lead where ' + whereStatement;
try{Integer Master = Database.countQuery(Query1);
}catch(Exception ex){ApexPages.addMessages(ex);
}
When I run this code e.g. with the whereStatement set to: Type__c = 'demo' (and the field Type__c doesn't exist on my Lead Object) I get an unhandled exception error and I can't seem to catch it in a nice way inside my code:
Apex script unhandled exception by user/organization: 00580000001gTj7/00D80000000ZWx3
Visualforce Page: /apex/MyVF_Count
System.Exception: No such column 'Type__c' on entity 'Account'. If you are attempting to use a custom field, be sure to append the '__c' after the custom field name. Please reference your WSDL or the describe call for the appropriate names.
On the other hand if the user enters a valid field but bad paramter, the exception is caught nicely (Type = "demo" ) in the try-catch block.
please help!