Timeline for List.add( value || 'default value')?
Current License: CC BY-SA 3.0
8 events
when toggle format | what | by | license | comment | |
---|---|---|---|---|---|
Feb 12, 2015 at 20:33 | vote | accept | ZAR | ||
Feb 12, 2015 at 18:59 | history | edited | Chris Duncombe | CC BY-SA 3.0 |
added 286 characters in body
|
Feb 12, 2015 at 18:51 | comment | added | Chris Duncombe | Learn something new everyday. I actually thought to myself '@sfdcfox would know the definitive answer to this', while i was typing out my comment. Always love learning something new. Thanks alot! | |
Feb 12, 2015 at 18:50 | comment | added | sfdcfox♦ |
I actually have a function like that in a class: public static Object nullValue(Object a, object b) { return a == null? b: a; } This makes it clear that I want one value or the other, just like the function nullValue in Visualforce/formulas: temp.add((String)Data.nullValue(j.Name, 'No Contact Name Associated'));
|
|
Feb 12, 2015 at 18:48 | comment | added | sfdcfox♦ |
temp.add(j.Name == null? 'No Contact Name Associated' : j.Name) . There's no need for an intermediary variable.
|
|
Feb 12, 2015 at 18:43 | comment | added | Chris Duncombe | I don't think I can combine those two lines into one. This is as minimal as I can think of to make it. I definitely could be wrong and would like to see if anyone else has suggestions, but this is all I can think of. | |
Feb 12, 2015 at 18:37 | comment | added | ZAR | Thanks! This absolutely works. I guess there's no way to do this in a shorter, more concise way? I try to keep my code as minimal as possible. If we can't come up with anything tighter, I'll definitely mark this as correct! Thank you! | |
Feb 12, 2015 at 18:33 | history | answered | Chris Duncombe | CC BY-SA 3.0 |