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
MarkInAtlantaMarkInAtlanta 

Newbie Apex calculation question

Looking in a calc heavy apex class i inherited.  Probably a newbie question but.. I see this form alot in the class: 

SumCurrentSalesValueB = SumCurrentSalesValueB + (line.Current_Sales_Value__c != null ? Integer.ValueOf(line.Current_Sales_Value__c):0);  

 I assume the use of  "Line.Current_Sales_Value__c != null ?"  is basicly a test with the ":0)" the replacement value if true?  Seems to do that.  

I looked high and low thru the Apex doc - can anyoue point me to the  correct reference for this..  
 
Best Answer chosen by MarkInAtlanta
surasura
this is not a apex (salesforce specifc) function it is called Ternary operator . it is available in most progaramming languages 

eg:

  ( age <30)? young: old      means 


if(age < 30)
{
   young
}
else
{
   old
}


refer  Trenary operator in this article https://developer.salesforce.com/docs/atlas.en-us.apexcode.meta/apexcode/langCon_apex_expressions_operators_understanding.htm

All Answers

surasura
this is not a apex (salesforce specifc) function it is called Ternary operator . it is available in most progaramming languages 

eg:

  ( age <30)? young: old      means 


if(age < 30)
{
   young
}
else
{
   old
}


refer  Trenary operator in this article https://developer.salesforce.com/docs/atlas.en-us.apexcode.meta/apexcode/langCon_apex_expressions_operators_understanding.htm
This was selected as the best answer
MarkInAtlantaMarkInAtlanta
thank you for the reference sura - that is what  i needed to know.