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
GMASJGMASJ 

If Condition ranges in apex

Hi, 
 
  I am confused with negative value adding in a condition This might be a simple question please suggestion 
  
   I need add below condition 
   Sales Ops  ==> [ Between 0.99 to 25 ] 
   CRO ==> [Between -10.01 to 0.00 ]
   CFO ==> [Between -10.00 to 25.01 ]
  
 I tried with below condition for some reason it does seems to be right Please suggest me how to add the range condition. 
   Decimal Dt = -12;
 
    If( Dt >= 0.99 && Dt <= 25.00){ 
        System.Debug('Sales Ops');
         }
    
    If( Dt >= -10.01 && Dt <= 0.00){ 
        System.Debug('CRO or SVP');    
         }
      
     if( Dt <= -10.00 && Dt >= 25.01){ 
        System.debug('CFO');
        }



Thanks
Sudhir





    


 
DevADSDevADS
Condition seems to be wrong. The valid conditions should be like below-
Decimal Dt = -12;

 If( Dt <= 0.99 && Dt <= 25.00){ 
     System.Debug('Sales Ops');
      }
 
 If( Dt <= -10.01 && Dt <= 0.00){ 
     System.Debug('CRO or SVP');    
      }
   
  if( Dt <= -10.00 && Dt <= 25.01){ 
     System.debug('CFO');
     }

Variable X can be greater only if the comparing value is on  the left side of the line, because the range is (-inifinity < 0 < infinity).

Hope this resolves your concern, Hit kudos if you like it.
GMASJGMASJ
Thanks for the suggestion in code  I still see an issue with this logic as well  Let me explain you how the logic should be 

  Sales Ops   >=  0.99   to    <+  25.00

  CRO            >= -10.01  to  <= 0.00

  CFO            <= -10.00  to   >= 25.01

  Example If enter 
   
     Value = 26 Only CFO must display 
     Value = -12  Only CFO must display
     Value = 0.77  Only Sales Ops must display 

 Hope this clarifies Please let me know how to add this logic. 

Thanks
Sudhir
 
DevADSDevADS
For Value = 26, The CFO condition (  CFO : X <= -10.00  to X >= 25.01)  would never satisfy because the value is not less than -10.

Rest examples are also wrong. Seems like you might need to use "OR" operator in condition because "AND" is always going to give you FALSE with your conditions.
GMASJGMASJ
Your right final condition will be a OR for CFO Below condition seems to be working
 
If( Dt >= 0.99 && Dt <= 25.00){ 
     System.Debug('Sales Ops');
      }
 
 If( Dt >= -10.01 && Dt <= 0.00){ 
     System.Debug('CRO or SVP');    
      }
   
  if( Dt <= -10.00 || Dt >= 25.01){ 
     System.debug('CFO');
     }

 

Thanks
Sudhir

DevADSDevADS
That's great. If you still need any help then post down here else hit kudos and mark best answer.

Regards,
DevADS