I try to access the value of a custom setting : this custom setting contains only one field Nombre__cand the name of the custom setting is Limit__c.

In apex I try to get the field Nombre__c :

Limit__c limite = Limit__c.getInstance('limit');
Integer nb = integer.valueOf(limite.Nombre__c);

There is only one value in this custom setting, named "limit" with a value in the field Nombre__c.

When I run my code I got this error

Attempt to de-reference a null object in the logs.

  • 1
    Try to add a debug log to check whether the value is there or not in limite.
    – RCS
    Jan 18, 2017 at 11:16
  • put system.debug('****limite *****'+limite ); to check what value you get in it and check if Nombre__c field has value in it. Jan 18, 2017 at 11:23

1 Answer 1


Here are possibilities what could be wrong:

  1. Limit__c limite = Limit__c.getInstance('limit');

May be limite variable is null as there was no custom setting record where name was 'limit'. If this is true syntax limite.Nombre__c will throw null pointer exception as you can not refer Nombre__c of null. So put a debug like

  1. In case point 1 above do not apply it may be the case value limite.Nombre__c is null It means there is a valid custom setting record with name as 'limit' but there is no value stored in Nombre__c field of that record.

    For this case try debugging


One of the above point will be true for your case.

You must log in to answer this question.

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