public class UpdateProduct{ public static void ProductName(Account[] accs){ for (Account a: accs){ if (a.ProductName__c == 'KarPower'){ a.KARPOWER__c = True; } } } }
===========================================
A TRIGGER is created on Account object to update the custom fields, which is more than 20 fields. So each time a user selects a product , the related name /custom field automatically gets CHECKED (a check mark is placed here).
What is the best approach to do that?
Should I create If statements for all of these 20 custom fields?
This is still a limitation, SWITCH CASE is not supported. However, it appears that with the roll out of the new compiler, this will become available (timeframe still not known). See the following article for more details: https://success.salesforce.com/ideaView?id=08730000000BrSIAA0
============================================
if(){
}
else if () {
}
.
.
.
else {
}
FYI - With Summer '18 release, Switch statements are supported in Apex!
https://developer.salesforce.com/docs/atlas.en-us.214.0.apexcode.meta/apexcode/langCon_apex_switch.htm
Thank you
switch on expression {
when value1 { // when block 1
// code block 1
}
when value2 { // when block 2
// code block 2
}
when value3 { // when block 3
// code block 3
}
when else { // default block, optional
// code block 4
}
}
expression can be of following types:
Integer
Long
sObject
String
Enum
If no when values match the expression, the when else block is executed.
Thanks,
KB