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
krish4ukrish4u 

about ? wildcard

Hi Friends,

contact.LastName = nameParts.size() > 1 ? nameParts[nameParts.size()-1] : nameParts[0];

in the above statement, the "?" what it will check and  what it means "nameParts[nameParts.size()-1] : nameParts[0]"

it isconfusing littlebit. please any one explain abt the line.

thanks,
Krish
Christoph EschweilerChristoph Eschweiler
Hi krish4u,

The line you posted contains a ternary operator. It is basically a shorter way for a one-line if-else statement.

It means:

if(nameParts.size() > 1)
{
    contact.LastName =  nameParts[nameParts.size()-1];
}
else
{
    contact.LastName =  nameParts[0];
}

Also check out the documentation (item 11) (https://www.salesforce.com/us/developer/docs/apexcode/Content/langCon_apex_expressions_operators_understanding.htm).

Best regards,

Chris
visuallifecycle.net
krish4ukrish4u
Thank you for the explanation.