Don't have an account?
Search for an answer or ask a question of the zone or Customer Support.
You need to sign in to do that
Sign in to start searching questions
Signup for a Developer Edition
Sign in to start a discussion
if(id=='1' or id=='2') acc='a:' ; else if(id=='3') acc='b:'; else acc=':';
(condition) ? (value_if_true) : value_if_false
string id='3'; string acc= (id == '1' || id== '2') ? 'a: ' : ((id == '3' ) ? 'b: ' : ''); system.debug('acc- '+acc); // Output will be acc- b
It is basically a terinary operator in salesforce
it is actually a replacement for we generally use this for conditional dataFormating in vf Page.
like say
style="{!if(opp.Name[THIS]=opp.Name[THIS -1],'color:gray', 'color:black')}"/>
Instead of the above , we use
style="{!opp.Name[THIS]==opp.Name[THIS -1]?'color:gray': 'color:black')}
IF(logical_test, value_if_true, value_if_false)
Example:
someVariable=(SomeOtherVariable == 'SomeValue'?TrueValue :FalseValue)
// someVariable will contain TrueValue if condition is true else will contain FalseValue
Thanks and Regards,
Shiva RV
You can execute below snippet in Anonymous window by changind id values as 1/2/3
Let me know if that helps you.
Best Regards,
BALAJI