In an application I am reading configuration values from a custom setting. This custom setting has a data set with a few fields, like username, password, enabled, and a few more.
ApiCredential__c is the name of the custom setting and the data set is called AppDettings.
I have a class called AppSettingsController which is used for displaying and updating the configuration values.
I have the following code:
ApiCredential__c objAppDetails;
try
{
System.debug('Checking if app details are set');
objAppDetails = ApiCredential__c.getValues('AppDetails');
}
catch(Exception ex)
{
System.debug('App details are not set');
}
For new apps, when the custom setting is not set, when this code runs an error occurs on the objAppDetails = ... line. The code does not go into the catch(Exception) statement.
How can I handle when a custom setting is not set?