(!GWB_Utility.isNull(cust.FinancialIndicator)?cust.FinancialIndicator == 'Y'? 'Yes':cust.FinancialIndicator == 'N'? 'No':null);

Idea - the value will be either Y/N/Null - If it's Y show Yes , N show No and null if null

Where am I going wrong?


Don't use multiple ternary operators in one line. It's way too confusing to be worth it. Here's what you have:

/*condition1*/ !GWB_Utility.isNull(cust.FinancialIndicator) ?
    /*truthy_value1*/ /*condition2*/cust.FinancialIndicator == 'Y' ?
        /*truthy_value2*/ 'Yes' :
        /*falsy_value2*/ /*condition3*/ cust.FinancialIndicator == 'N' ?
            /*truthy_value3*/ 'No' :
            /*falsy_value3*/ null;

You are missing /*falsy_value1*/.

I advise using a more verbose if/else syntax here. It will be much easier to work with:

String output;
if (input == 'Y') output = 'Yes';
if (input == 'N') output = 'No';

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.