• Elie Wahnoun
  • NEWBIE
  • 10 Points
  • Member since 2016

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 1
    Questions
  • 1
    Replies
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:
 
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.
 
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:
 
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.