function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
Abhishek Kumar 149Abhishek Kumar 149 

what is meaning of below code.

acc= (id == '1' || id== '2') ? 'a: ' : ((id == '3' ) ? 'b: ' : '');
Shiva RajendranShiva Rajendran
Hi Abhishek,

It is basically a terinary operator in salesforce
it is  actually a replacement for 
if(id=='1' or id=='2')
  acc='a:' ;
else if(id=='3')
acc='b:';
else
acc=':';
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
BALAJI CHBALAJI CH
It's like IF condition. 
​(condition) ? (value_if_true) : value_if_false
For the above condition., if id ==1 or id ==2, then acc will be 2., else if id id == 3, then acc = 2., else acc=''

You can execute below snippet in Anonymous window by changind id values as 1/2/3
string id='3';
string acc= (id == '1' || id== '2') ? 'a: ' : ((id == '3' ) ? 'b: ' : '');
system.debug('acc- '+acc); 
// Output will be acc- b

Let me know if that helps you.

Best Regards,
BALAJI