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
Suneel14Suneel14 

Lead Auto Response stop working after adding after insert trigger on lead

Hi, 

 

I wrote a trigger(After Insert) which updates one fields of Lead, but after implementing trigger Auto Response Rule stop working, i searched about it and i found some soluction but that soluction is not working. Could any one help me regarding this.

following is the code : 

 

*/
trigger LeadTrigger on Lead (after insert) {
try {
if(trigger.isAfter) {
set<Id> leadId = new set<Id>();
list<String> clubName = new list<String>();
list<Account> accList = new list<Account>();
list<Lead> leadList = new list<Lead>();
list<Lead> leadListUpdate = new list<Lead>();

for(Lead leadObj : Trigger.new) {

leadId .add(leadObj.Id);
clubName .add(leadObj .Club__c);
}
accList = [select id , Name from Account where Name IN : clubName];

leadList = [select id , Club__c,P_Club__c from Lead where ID IN : leadId ];
for(Lead ldObj :leadList) {


Database.DMLOptions dlo = new Database.DMLOptions();
dlo.EmailHeader.triggerAutoResponseEmail = true;
ldObj.setOptions(dlo);


for(Account accObj :accList) {
if(ldObj.Club__c == accObj.Name) {
ldObj.P_Club__c = accObj .Id;
leadListUpdate.add(ldObj);
}
}

}
if(leadListUpdate.size() >0) {
update leadListUpdate;
}
}

} catch(Exception e) {
}
}