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
Peter Martensen 8Peter Martensen 8 

Need help adding another exclusion to a Class

I have a Class that sends an email when an Opportunity is Closed Won and if the Line_of_Service__c does not contain “Agawam”.  I need to add “Whippany” and “Mirabel” to that exclusion.  Can someone help me modify this code to exclude those also?
 
       
List<Opportunity> oppsThatGetAlerts = new List<Opportunity>();
        for( Opportunity o : updatedOpportunities ) {
            // 11-08-2016 jhm: If the Opp just went to Closed Won and it's from Durham, NC or Longmount, CO, Edinburgh we want to send an alert.
            if( ('Closed Won' == o.StageName) && ('Closed Won' != opportunityOldMap.get(o.Id).StageName) && (!o.Line_of_Service__c.contains('Agawam') ) ) {
                System.debug('*******');
                oppsThatGetAlerts.add( o );
            }
        }
        if( 0 < oppsThatGetAlerts.size() ) {
           sendOppAlerts( oppsThatGetAlerts );
        }

 
Best Answer chosen by Peter Martensen 8
Yash ShuklaYash Shukla
you can go on adding your further exclusion values with && operator as in line 4

All Answers

Yash ShuklaYash Shukla
you can go on adding your further exclusion values with && operator as in line 4
This was selected as the best answer
ismailismail

Hi Peter,
You can do it easily like below;

Short brief; first defining all exclude list,
then making your current value similar to them,
and comparison with indexOf.

// define all excluded values with double #'s to not to mismatch anything else ) 
String excludedLines =  '##Whippany##Mirabel##Agawam##'; // also you can read these values from system config.. 
String currentLine = '##' + o.Line_of_Service__c + '##';
if( 
    ('Closed Won' == o.StageName) && 
    ('Closed Won' != opportunityOldMap.get(o.Id).StageName) &&
    (excludedLines.indexOf(currentLine) < 0 ) 
  ) 
{