+ Start a Discussion
Pavan777Pavan777 

Lead assignment email notification

Hello everyone,
I am facing a weird problem when updating lead owner based on some criteria in my trigger.I am getting two emails, one the default one from salesforce(out of box email functionality) and the other is a custom email triggered from my trigger. Is there any way we could restrict the salesforce default email or can we update the template that's being used for this out of box functionality?
(We don't have any auto response / assignment rules defined in the org)

Thanks in advance.

Pavan.

sh-at-youseesh-at-yousee

Hi,

 

It's quite difficult to know what to suggest without any knowledge of your trigger and/or org. setup but a guess from my end could be that you have defaulted the "notify owner" checkbox on leads so that owners are default notified when a lead is assigned to them.

 

If I remember correctly you change this in Layout Properties on your lead page layouts.

 

I have no idea if that's it or not but if not please supply your trigger code in your reply.

 

Hope this helps.

 

/Søren Nødskov Hansen

Pavan777Pavan777

Thanks Hansen for the quick response.

 

 "Notify Default Lead Owner " checkbox in our org was already unchecked but still we've this issue. I've before update trigger on lead and was trying to update lead owner based on some conditions. Below is the trigger code, Lead assignment to new owner is working fine but having problems with email notification i.e. two emails being send to lead owner one through out of box functionality and other through my custom code.

 

 Map<String,String> emailMap = new Map<String,String>();
        Map<String,String> userName = new Map<String,String>();
        List<Messaging.SingleEmailMessage> emailList = new List<Messaging.SingleEmailMessage>();
        
        for(Lead_Assignment_Mapping__c leadAssignmentRecord : [Select Brand__c,Channel__c,County__c,User__c,User__r.email,User__r.Name from Lead_Assignment_Mapping__c where County__c in :Markets and Brand__c in :BrandsList and Channel__c in :Channel order by User__r.Name desc limit 1000])
        {
            assignmentMap.put(leadAssignmentRecord.County__c+'-'+leadAssignmentRecord.Brand__c+'-'+leadAssignmentRecord.Channel__c,leadAssignmentRecord.User__c);
            emailMap.put(leadAssignmentRecord.User__c,leadAssignmentRecord.User__r.email);
            userName.put(leadAssignmentRecord.User__c,leadAssignmentRecord.User__r.Name);
        }  
        //Assign leads accordingly
        for(Lead lead : leads)
        {
               Set<String>Owners = new Set<String>();
               List<String> Owner = new List<String>();
               integer index = 0;
               
               //uncheck the check box and populate the auto assigned date
               lead.Last_Date_of_Auto_Assignment__c = System.Today();
               lead.Assign_Lead_Using_Rules__c = false;
               for(String brnd : lead.Interested_MC_Brands__c.split(';'))
               {
                   if(assignmentMap.get(lead.County__c+'-'+brnd+'-'+lead.Channel__c) != Null)
                   {
                       Owners.add(assignmentMap.get(lead.County__c+'-'+brnd+'-'+lead.Channel__c));
                   }    
               }
               Database.DMLOptions dlo = new Database.DMLOptions();
               //dlo.EmailHeader.triggerUserEmail = false;
               dlo.EmailHeader.triggerAutoResponseEmail= false;
               Owner.addAll(Owners);
               List<String> toAddresses = new List<String>();
               if(Owner.size() > 0)
               {
                       //Random user selection logic
                       do{
                           index = (Math.Random()*10).intValue();
                           if(index > 1)
                               index--;
                        }while(Owner.size()-1 < index);
                       //Assign the appropriate owner
                       
                       if(Owner.size() > 1 && Owner[index] != Null)
                       {
                           lead.ownerId = Owner[index];
                       }
}
sh-at-youseesh-at-yousee

Hi Pavan777,

 

Is it me or is something of the trigger missing? I never see the you use emailList - where exactly do you send your custom email?

 

Another thing I wanted to ask was if you are assigning the leads to an acutal User of a queue?

 

If you are assigning them to queues maybe you have defined some sort notification email for those queues which spawn the "out of the box" email.

 

/Søren Nødskov Hansen

Pavan777Pavan777

Hansen,

Just to clarify we don't have any queues defined in the org and i am just assigning lead to one of the users with in the org.

I've not included the code for email in my earlier post as it is pretty straight forward...

 

Thanks,

Pavan.

SiddoSiddo

Is it possibly another WF rule created? what do the templates look like?