1

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.

2
  • 1
    Try to add a debug log to check whether the value is there or not in limite.
    – RCS
    Jan 18 '17 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 '17 at 11:23
2

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

System.debug('limite==='+limite);
  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

System.debug('limite.Nombre__c==='+limite.Nombre__c);

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

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.