I need to define a clause for my dynamic SOQL query, based on the value in my userRegion
variable, by adapting the query from this answer.
When I try to use
String queueOwnerRegionClause = ( userRegion == 'Asia' ? ' Asia__c = TRUE ' :
( userRegion == 'EU' ? ' EU__c = TRUE ' :
( userRegion == 'NA' ? ' NA__c = TRUE ' )));
I get these errors
Incompatible types in ternary operator: Boolean, String
(error location: 2nd line)
unexpected syntax: 'mismatched input ')' expecting COLON'
(3rd line)
adding a colon at the end of the 3rd line causes this error instead
unexpected token: ')'
(3rd line)
There's obviously a simple fix for these errors but I've tried searching for examples of other SOQL that create clauses by using this method & can't find any. I'm not sure which other search terms to use.
What's the correct syntax to use to set the criteria for this clause?
(boolean ? string : string)
. See e.g. stackoverflow.com/questions/7407273/…. Though the code would be clearer (and more likely to compile) using series ofif
statements.String s = b ? 'abc' : 'xyz';
where they work really well.