Skip to main content

Questions tagged [ternary-operator]

The tag has no usage guidance.

Filter by
Sorted by
Tagged with
2 votes
1 answer
94 views

Apex: Ternary operator and SonarQube warning

I have the following Boolean assignemnt: Contact currentContact = new Contact(); currentContact.Is_Manager__c = UserWrapper.isManager() != null ? UserWrapper.isManager() : false; UserWrapper class ...
Teo's user avatar
  • 21
0 votes
1 answer
284 views

Apex ternary operator - Error: Compile Error: Expression cannot be a statement

Trying to simplify multifle if-else conditions . Below code is throwing error " Error: Compile Error: Expression cannot be a statement. " . Can you please let me know how to resolve the ...
Hemant-2's user avatar
0 votes
2 answers
618 views

How to rewrite that ternary operator code to if-else?

I can't understand that part of the code - how to rewrite this to if-s and else? Especially the partthis.map1?.containsKey(custom_object__c?.workflow_status__c) List<custom_object_2__c> ...
Fgh999's user avatar
  • 35
1 vote
1 answer
12k views

A special ternary condition in apex (safe navigation operator)

I've seen this somewhere, sometime before but I can't remember how it's used and I can't find anything about it online (Probably because I don't know what to search for). So please help me understand ...
Bahman.A's user avatar
  • 868
9 votes
2 answers
4k views

Ternary Operator Compile Failure. Incompatible types in ternary operator

Assume we have some code in Apex: APEX Boolean isString = true; // or false List<String> labels = new List<String>{ 'Label' }; Object entity = isString ? labels.get(0) : ...
Oleh Berehovskyi's user avatar