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
gregj777gregj777 

Auto-response email on lead

I have a Lead trigger which assigns leads to SF users and sends them an email. Based on certain variblesa we don't want the auto email to be sent to a specific user email address. 

I adjusted the users email settings so they don't get the email notifications but it doesn't seem to work. Is it possible the below trigger(SEE BELOW) is over riding the email notification settings?

 

/*
    Author: Sarah Khalid
    Date: 06/07/2010
    Description: This trigger carries out lead assignment and parses out the title field coming from Netsuite
                 into 4 different fields on the lead object
                 
                 Added the New Lead Assignment on 20-Jan-2012 by Alex
*/

trigger ParseSourceInformation on Lead (before insert, before update) 
{
    system.debug('In LeadAssignment trigger');
    
    ConvertLeadHelper helper = new ConvertLeadHelper();
    LeadAssignmentHelper assignmentHelper = new LeadAssignmentHelper();
    Id leadOwner;
    
    //Variables added by Alex for new Lead Assignment. 
    
    //Variables to stroe the Active Users info.
    Map<Id, String> userIdUsernameMap = new Map<Id, String>();
    Map<String, Id> usernameUserIdMap = new Map<String, Id>();
    
    //Variables used to store the Custom Setting values.
    Set<String> leftUserIds = new Set<String>();
    String conversionEvent;
    String homeCustomerSegment;
    String recentConversionEvent;
    String countryNA;
    String countryCanada;
    String stateOrCountry;
    map<String, String> roundRobinUsers = new Map<String, String>();
    
    //Latin America Countries
    Set<String> latinAmericaCountries = new Set<String>{'ARGENTINA', 'BOLIVIA', 'BRAZIL', 'CHILE', 'COLOMBIA', 'ECUADOR', 'FRENCH GUIANA', 'GUYANA', 'PARAGUAY', 'PERU', 'SURINAME', 'URUGUAY','VENEZUELA' };
    
    //Get Usernames from Custom Setting.
    Map<String, Lead_Assignment__c> leadAssignment = Lead_Assignment__c.getAll();
    
    //Round Robin Count update
    List<Round_Robin_Count__c> updateRrc = new List<Round_Robin_Count__c>();
    
    //Store the values from Custom setting to variable.
    for( String tempName : leadAssignment.keySet() ){
    
        if( leadAssignment.get(tempName).Order_of_Execution__c == 1 ) leftUserIds.add( leadAssignment.get(tempName).Username__c );
        if( leadAssignment.get(tempName).Order_of_Execution__c == 2 ) conversionEvent       = leadAssignment.get(tempName).Username__c;
        if( leadAssignment.get(tempName).Order_of_Execution__c == 3 ) homeCustomerSegment   = leadAssignment.get(tempName).Username__c;
        if( leadAssignment.get(tempName).Order_of_Execution__c == 4 ) recentConversionEvent = leadAssignment.get(tempName).Username__c;
        if( leadAssignment.get(tempName).Order_of_Execution__c == 5 ) countryNA             = leadAssignment.get(tempName).Username__c;
        if( leadAssignment.get(tempName).Order_of_Execution__c == 6 ) countryCanada         = leadAssignment.get(tempName).Username__c;
        if( leadAssignment.get(tempName).Order_of_Execution__c == 7 ) stateOrCountry        = leadAssignment.get(tempName).Username__c;
        if( leadAssignment.get(tempName).Order_of_Execution__c == 8 ) roundRobinUsers.put( tempName, leadAssignment.get(tempName).Username__c );
    }
    
    //Get User info.
    for( User u : [ SELECT Id, Username FROM User WHERE isActive = TRUE ] ){
    
        userIdUsernameMap.put( u.id, u.Username );
        usernameUserIdMap.put( u.Username, u.id );
    }
        
        
        
    for (Lead currentLead : Trigger.new)
    {   
        String foundSiteVia = currentLead.hubspot__Found_Site_Via__c;
        Double qualificationScore = currentLead.QualificationScore__c;
        String country = currentLead.Country;
         
        system.debug('Title = ' + currentLead.Title);
        system.debug('Country = ' + country);
        system.debug('Recent Event = ' + currentLead.hubspot__Recent_Conversion_Event__c);
        
        if(foundSiteVia!=null || foundSiteVia!='')
        {
            string source = helper.parseSource(foundSiteVia);
            string sourceDetail = helper.parseSourceDetail(foundSiteVia);
            currentLead.Source__c = source;
            currentLead.Source_Detail__c = sourceDetail;
        }
            
        /* Lead Assignment Starts here */
        //Start out with Occupation, HearAboutIdeaPaint and Country field and see if they match with lead assignment criteria
        //string occupation = currentLead.Occupation__c;
        //string hearAboutUs = currentLead.HowHearAboutIdeaPaint__c;
        //string state = currentLead.State;
        
        //This boolean determines if the lead assignment criteria was met or not so that a lead should be further processed
        boolean processed = FALSE;
        
        //string groupName;
        system.debug('Lead Assignment Starts here');
        
        //Only process lead assignment if the lead is initially assigned to Marcus
        if(currentLead.OwnerId=='00530000003UZTR')
        {
             //Check for Existing LeadOwner is not available in Exclude list
            if( !leftUserIds.contains( userIdUsernameMap.get( currentLead.ownerId ) ) ) {
        
                if( processed != TRUE && ( (currentLead.hubspot__Conversion_Events__c != NULL && currentLead.hubspot__Conversion_Events__c == 360) || (currentLead.Title != NULL && currentLead.Title.Contains('GMA')) )){
            
                    currentLead.OwnerId = usernameUserIdMap.get( conversionEvent ); 
                    processed = TRUE;
                }
                
                if( processed != TRUE && ( currentLead.WhereWantUseIdeaPaint__c != NULL && currentLead.WhereWantUseIdeaPaint__c == 'Home' )){
                    
                    if ( currentLead.hubspot__Recent_Conversion_Event__c != NULL && currentLead.hubspot__Recent_Conversion_Event__c.toUpperCase().Contains('VISITED PLAN YOUR INSTALLATION PAGE' )){
                    }else {
                        currentLead.OwnerId = usernameUserIdMap.get( homeCustomerSegment );
                        processed = TRUE;
                    }
                }
                
                //User - IdeaPaint Web
                if( processed != TRUE && ( currentLead.hubspot__Recent_Conversion_Event__c != NULL && currentLead.hubspot__Recent_Conversion_Event__c.toUpperCase().Contains('PURCHASE') )){
                
                    currentLead.OwnerId = usernameUserIdMap.get( recentConversionEvent );
                    processed = TRUE;
                }
                
                if( processed != TRUE && ( currentLead.Country != NULL && currentLead.Country.toUpperCase() != 'UNITED STATES' && currentLead.Country.toUpperCase() != 'USA' && currentLead.Country.toUpperCase() != 'CANADA' && !(latinAmericaCountries.contains( currentLead.Country.toUpperCase()))  )){
                
                    currentLead.OwnerId = usernameUserIdMap.get( countryNA );
                    processed = TRUE;
                }
                
                if( processed != TRUE && ( currentLead.Country != NULL && currentLead.Country.toUpperCase() == 'CANADA' )){
                
                    currentLead.OwnerId = usernameUserIdMap.get( countryCanada );
                    processed = TRUE;
                }
                
                if( processed != TRUE && ( (currentLead.State != NULL && ( currentLead.State.toUpperCase() == 'CA' || currentLead.State.toUpperCase() == 'CALIFORNIA' )) || (currentLead.Country != NULL && latinAmericaCountries.contains( currentLead.Country.toUpperCase())) )){
                
                    currentLead.OwnerId = usernameUserIdMap.get( stateOrCountry );
                    processed = TRUE;
                }
                
                //Round Robin User assignment.
                if( processed != TRUE ){
                
                    if( roundRobinUsers.size() > 0 ){
                    
                        Round_Robin_Count__c rrc = Round_Robin_Count__c.getOrgDefaults();
                                               
                        currentLead.OwnerId = usernameUserIdMap.get(Lead_Assignment__c.getValues('Round Robin User-'+String.valueOf( math.mod( Integer.valueOf( rrc.Round_Robin_Count__c), roundRobinUsers.size() ) + 1 )).Username__c);
                        rrc.Round_Robin_Count__c++;
                        updateRrc.add( rrc );
                        processed = TRUE;
                    }
                }//End of Round Robin User assignment.
            }//End of Exclude list check.
        }
        
            
        //Parse out the title field here
        String[] titleArray = new String[3];
        if(currentLead.Title!=NULL && currentLead.Title.length()>5 && currentLead.Title.contains(',')) 
        {
            titleArray = currentLead.Title.split(',');
            currentLead.Quantity__c = Double.valueOf(titleArray[0]);
            currentLead.Item_Type__c = titleArray[1];
            currentLead.Color__c = titleArray[2];
            currentLead.Amount__c = Double.valueOf(titleArray[3]);
            currentLead.TotalOrder__c = titleArray[3];
        }
        currentLead.Title = '';     
    }
    
    if( updateRrc.size() > 0 ) {
    
        update updateRrc;
    }
       
    //No need to update lead it updates explicitly
}