+ Start a Discussion
lnryanlnryan 

Null Pointer Exceptions from Customer Settings Checkbox fields

I'm getting a null pointer exception when I try to use evaluate a checkbox field from my BusinessChannels__c custom setting and the checkbox is unchecked. It seems like kind of a joke to have to set up an if statement like

 

if(null!=bc.get('somefield__c')&&(Boolean) bc.get('somefield__c'))...

 instead of simply

if((Boolean) bc.get('somefield__c'))...

 or simpler

if(bc.get('somefield__c'))...

 

 

am i missing something obvious? thanks!

 

User@SVFUser@SVF

Inryan,

 

try this syntax

bc.getInstance('somefield__c')
lnryanlnryan

leider nicht.

 

the getInstance(String) method returns a record from the custom settings set, not a field within that instance.

 

bc.getInstance('somefield__c'); 

>>Method does not exist or incorrect signature: [SOBJECT:BusinessChannels__c].getInstance(String)

 

  

User@SVFUser@SVF

Try some thing like this... Not sure though.

 

 

BusinessChannels__c myBC1 = BusinessChannels__c.getValues('United States');
String myBCVal = myCS1.Some_Field__c;

 Replace 'United States' with the name of the custom setting record you wanna retrieve.

 

Thanks

 

lnryanlnryan

Thank you for your suggestions. Perhaps my question was unclear:

 

I am not have trouble retrieving datasets from Custom Settings. I am asking if there is a better way to error-proof a null value in a checkbox field than a two part if statement in the form of if(null!=field&&field).