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
Mel LisauMel Lisau 

How can i use a ternary operator with multiple lines of code ?

Hi,
I am using a ternary operator like the following 
MyObject has a field "Name"



String WebSite = ‘Yahoo.com’;
String WebSiteResult = WebSite != null ? WebSite : ‘Google.com’;

But how can i do something like this 

MyObject obj = new MyObject();
String WebSite = ‘Yahoo.com’;
String WebSiteResult = WebSite != null ? { WebSite; obj.Name ='TestName' } : ‘Google.com’;
It says invalid '  {"

 
Kanav TechfineryKanav Techfinery
Hi Mel,

I do not think you can write multiple lines of code (;) inside a ternary operator. Just for curiosity, what is the need to set the Website and obj.Name inside the ternary operator?