You need to sign in to do that
Don't have an account?
Elie Wahnoun
Pardot/SFDC - Lead Distribution Issue - Lead Trigger
Hi all,
I am experiencing issues with the “Lead Trigger” that has been developed for us. Our leads, coming in through Pardot, are being stuck in the que. I reached out to the SFDC supprt team and the told me the issue arises from the Lead Trigger. .
This is the error we are getting from Pardot:
LeadTrigger: execution of BeforeInsert caused by: System.NullPointerException: Attempt to de-reference a null object Trigger.LeadTrigger: line 27, column 1 | CANNOT_INSERT_UPDATE_ACTIVATE_ENTITY
Any direction as how to fix this would be truly helpful.
For your reference, here is the code of the LeadTrigger:
Thank you in advance for your time.
I am experiencing issues with the “Lead Trigger” that has been developed for us. Our leads, coming in through Pardot, are being stuck in the que. I reached out to the SFDC supprt team and the told me the issue arises from the Lead Trigger. .
This is the error we are getting from Pardot:
LeadTrigger: execution of BeforeInsert caused by: System.NullPointerException: Attempt to de-reference a null object Trigger.LeadTrigger: line 27, column 1 | CANNOT_INSERT_UPDATE_ACTIVATE_ENTITY
Any direction as how to fix this would be truly helpful.
For your reference, here is the code of the LeadTrigger:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 | trigger LeadTrigger on Lead (before insert, before update) { Set<String> codeSet = NEW Set<String>(); Map<String,String> regionMap = new Map<String,String> (); if(Trigger.isInsert){ for(Lead LD :Trigger.new){ if(LD.Phone <> NULL){ String numericPhone = LD.Phone.replaceAll('[^0-9]', ''); String areaCode = numericPhone.substring(0,3); codeSet.add(areaCode); } } } if(Trigger.isUpdate){ for(Lead LD :Trigger.new){ if(LD.Phone != Null && LD.Phone <> Trigger.oldMap.get(LD.id).Phone){ String numericPhone = LD.Phone.replaceAll('[^0-9]', ''); String areaCode = numericPhone.substring(0,3); codeSet.add(areaCode); } } } IF(!codeSet.isEmpty()){ for(Region_Lookup__c ch:[select Name,Area_code__C from Region_Lookup__c where Area_code__C IN:codeSet]){ regionMap.put(ch.Area_code__C,ch.Name); } for(Lead LD :Trigger.new){ String numericPhone = LD.Phone.replaceAll('[^0-9]', ''); String areaCode = numericPhone.substring(0,3); if(regionMap.containsKey(areaCode)){ LD.Lead_Region__c = regionMap.get(areaCode); } } } } |
Thank you in advance for your time.
Try replacing the for trigger with the following (I added a check for null and empty values around the Phone field):
Also, when you post code on here, please use the code format button (< >). It helps make the code a bit more readable and allows repliers to copy and paste if necessary. Thanks
All Answers
Try replacing the for trigger with the following (I added a check for null and empty values around the Phone field):
Also, when you post code on here, please use the code format button (< >). It helps make the code a bit more readable and allows repliers to copy and paste if necessary. Thanks
Thank you so much for your answer.
It think it will work. Although, not being a develloper, I am unable to actualyl edit it because the LeadTrigger is in production.
Any help on that end?
Browsed quickly online, and it seems this cannot be edited because it is an active org.
Thoughts?
Thanks.