0

I encountered an issue in which I got a NULL error because a particular picklist didn't have the value that I wanted when the language of the user is set to French.

For example, I have a picklist called 'Status' and it has a value called 'Closed'. However, when the user change his language to French, the value changes to 'Clos'.

Now in my Apex class, I needed to filter only records with Status 'Closed' so I have an If Condition that looks something like this:

if(sobj.Status == 'Closed') { //do something }

Now since the language is in French, the Status 'Closed' is translated to 'Clos' so when the code runs and goes to the above if condition, the result will be false and the code inside the if statement will not run.

Thus, I need to also add the French translation of 'Closed' to the condition but this seems to me very tedious and I'm now doing more hardcoding.

if(sobj.Status == 'Closed'|| sobj.Status == 'Clos' ) { //do something }

Is there any other way we can solve this issue? Thanks.

  • 1
    can you double check, that this is a source of your null pointer exception? SOQL has toLabel function that translates picklist field value to current user's language. Without this function API Name of picklist is returned. – Oleksandr Berehovskyi Nov 29 '17 at 9:02
  • can you post code snipped of soql query and part, where you are facing exception – Oleksandr Berehovskyi Nov 29 '17 at 9:12

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.