Inspector flags value casing on Switch statements for certain types.
The following code sample compiles fine but in the IC editor, it flags it with a warning citing improper casing (see screenshot).
public String translateDisplayType(Schema.DisplayType dt) {
//Proper Case
switch on dt {
when Boolean {
return null;
}
when Currency, Integer, Double {
return null;
}
when Date, Datetime {
return null;
}
when String {
return null;
}
}
//All Caps
switch on dt {
when BOOLEAN {
return null;
}
when CURRENCY, INTEGER, DOUBLE {
return null;
}
when DATE, DATETIME {
return null;
}
when STRING {
return null;
}
}
}
Comments (7)
-
repo owner -
repo owner By the way, according to Salesforce, the proper case would be the CONSTANT_CASE version, e.g., the following from the OST as designated by Salesforce's Tooling API:
global enum /*Schema.*/DisplayType { ADDRESS, ANYTYPE, BASE64, BOOLEAN, COMBOBOX, COMPLEXVALUE, CURRENCY, DATACATEGORYGROUPREFERENCE, DATE, DATETIME, DOUBLE, EMAIL, ENCRYPTEDSTRING, ID, INTEGER, JSON, LOCATION, LONG, MULTIPICKLIST, PERCENT, PHONE, PICKLIST, REFERENCE, SOBJECT, STRING, TEXTAREA, TIME, URL }
I realize that's at odds with what they document online, but that's how the API reports it, and IMO it's more consistent with how enum constants should be defined anyway.
-
reporter Agreed. To me, they are constants within a class and should be all uppercase. I wouldn't mind some underscores in between words but that might just be me :)
-
repo owner Agreed. Unfortunately this is part of the standard Apex system API so it's not at all under my control. I'll take care of the incorrect reference injection which will resolve this code inspection false negative, though.
-
repo owner Fix submitted for the next build.
-
reporter Thanks! Appreciate it.
-
repo owner - changed status to resolved
Delivered in 2.0.4.3 and 1.8.4.2.
- Log in to comment
Thanks, John. Easily reproduced, of course. The issue is that IC is incorrectly injecting a reference to the data type in addition to the correct reference to the enum constant:
Should be easy enough to fix. I'll see if I can slot it into the next build.