Questions tagged [switch-case]

The tag has no usage guidance.

Filter by
Sorted by
Tagged with
8
votes
1answer
155 views

Most efficient way to switch on SObjectType?

It is a bit odd we can't evaluate a switch statement directly on SObjectType, so I am trying to determine conclusively which workaround is the most efficient. Just to verify, I tried to compile this ...
7
votes
1answer
1k views

Switch: Enum value used in 'when expression' should be unqualified

Background I am getting this error message three times: Enum value used in 'when expression' should be unqualified In relation to this code: Schema.DisplayType fieldType = getType(fieldName); ...
0
votes
4answers
104 views

How can I access variable in switch case outside of switch block?

I am trying to upsert a dynamic sObject list of records using Database.Upsert, I want to be able to use AllOrNone parameter however this returns an error saying that my toUpsert variable must be a ...
5
votes
1answer
406 views

Good approach to making switch on string values case insensitive?

In Apex the == operator is case-insensitive for strings and in other places case insensitivity is supported. But the recently introduced switch is case sensitive. The workaround of moving to one case ...
6
votes
2answers
165 views

Using newly released feature on an apex class having older API version

As you all probably know switch has been introduced in Summer'18 (API v43,0) release. I have started using it in my apex class which is having API version 36,0 and somehow it works in my sandbox. I ...
8
votes
2answers
1k views

Best Practice discussion: Difference between SWITCH and IF/ELSE-IF/ELSE? [closed]

NOTE: This is not an opinion-based question. Developers often debate the best way to code ways to do the same thing. Please don't close this as opinion-based. It's a good reference for people choosing ...
7
votes
1answer
460 views

System.TriggerOperation enum

Any examples how to use new System.TriggerOperation enum in a trigger? How this code could be replaced: trigger TriggerName on ObjectName (before delete, before insert, before update, after delete,...