3

Is there a way to say do nothing in a ternary if statement? Currently i have it set to just equal itself on true. Would it be better programming to do this another way?

Example:

Id userID = ApexPages.currentPage().getParameters().get('id');
userID = (userID != null) ? userID : UserInfo.getUserId();

1 Answer 1

4

This isn't using ternary if, but it achieves the result that you are looking for and I think it's clear to understand...

Id userID = ApexPages.currentPage().getParameters().get('id');
if (userID == null) userID = UserInfo.getUserId();
1
  • 2
    Yeah, that makes sense. If there is only one outcome then there would be no need to use a ternay if, seeing as how there is no need to do an else. You helped me realize my mistake
    – Tyager
    Jun 30, 2015 at 14:15

You must log in to answer this question.

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