• erikrussel
  • NEWBIE
  • 0 Points
  • Member since 2011

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 3
    Questions
  • 5
    Replies

Error:Apex trigger UpdateCountyInfo2 caused an unexpected exception, contact your administrator: UpdateCountyInfo2: execution of AfterUpdate caused by: System.NullPointerException: Attempt to de-reference a null object: Trigger.UpdateCountyInfo2: line 20, column 74

 

I recieved the following error when trying to save a record.  Hoping someone could help/provide some insight on this?  Below is my trigger.

 

trigger UpdateCountyInfo2 on Lead(after insert,after update) {
Set<Id> assIdSet=new Set<Id>();

   for(Lead l:Trigger.new)
   {
       if(l.Postal_Code_LookUp_Field__c != null) {
     
        assIdSet.add(l.Name);
        }
    }
   

       if(assIdSet.size()>0){
      Map<Id,sundog_deprm2__Postal_Code__c> assMap = new Map<Id,sundog_deprm2__Postal_Code__c>([Select Id,Name,sundog_deprm2__County__c from sundog_deprm2__Postal_Code__c where Id IN: assIdSet]);
     
         for(Lead LD:Trigger.new)
         {
           if(LD.Postal_Code_LookUp_Field__c !=null) 
           {
               LD.County__c = assMap.get(LD.Postal_Code_LookUp_Field__c).sundog_deprm2__County__c; 

          }

         else{

                   LD.County__c=null;

                 }
                 }
                 }
                 }

When attetempting to pass a field value from one object (cutom object) to a another object (Lead) does the related field need to be a Unique ID?  If the custom object is an installed package and doesn't already contain a unique ID field can I create a lookup field and use that a related field?

 

Thanks

Erik

Hello.  I have very little coding experence and was hoping someone could help me with what I'd think should rather be a rather simple Apex Trigger.  Thanks in advance.

 

I have a custom object called sundog_deprm2__Postal_Code__c which has a field called sundog_deprm2__County__c.  I have a custom field on the lead object called County__c.  I just want to pass the value from that sundog_deprm2__County__c field to the County__c lead field.  

 

Here is what I tried to write to no avial.

 

trigger CountyInsert on Lead (after insert)
{
list<sundog_deprm2__Postal_Code__c> PostalCodes = [select  Id, Name,sundog_deprm2__County__c from sundog_deprm2__Postal_Code__c w];

for (Lead lead : Trigger.new) {

County__c=lead.County_c;



}
}

Error:Apex trigger UpdateCountyInfo2 caused an unexpected exception, contact your administrator: UpdateCountyInfo2: execution of AfterUpdate caused by: System.NullPointerException: Attempt to de-reference a null object: Trigger.UpdateCountyInfo2: line 20, column 74

 

I recieved the following error when trying to save a record.  Hoping someone could help/provide some insight on this?  Below is my trigger.

 

trigger UpdateCountyInfo2 on Lead(after insert,after update) {
Set<Id> assIdSet=new Set<Id>();

   for(Lead l:Trigger.new)
   {
       if(l.Postal_Code_LookUp_Field__c != null) {
     
        assIdSet.add(l.Name);
        }
    }
   

       if(assIdSet.size()>0){
      Map<Id,sundog_deprm2__Postal_Code__c> assMap = new Map<Id,sundog_deprm2__Postal_Code__c>([Select Id,Name,sundog_deprm2__County__c from sundog_deprm2__Postal_Code__c where Id IN: assIdSet]);
     
         for(Lead LD:Trigger.new)
         {
           if(LD.Postal_Code_LookUp_Field__c !=null) 
           {
               LD.County__c = assMap.get(LD.Postal_Code_LookUp_Field__c).sundog_deprm2__County__c; 

          }

         else{

                   LD.County__c=null;

                 }
                 }
                 }
                 }

When attetempting to pass a field value from one object (cutom object) to a another object (Lead) does the related field need to be a Unique ID?  If the custom object is an installed package and doesn't already contain a unique ID field can I create a lookup field and use that a related field?

 

Thanks

Erik

Hello.  I have very little coding experence and was hoping someone could help me with what I'd think should rather be a rather simple Apex Trigger.  Thanks in advance.

 

I have a custom object called sundog_deprm2__Postal_Code__c which has a field called sundog_deprm2__County__c.  I have a custom field on the lead object called County__c.  I just want to pass the value from that sundog_deprm2__County__c field to the County__c lead field.  

 

Here is what I tried to write to no avial.

 

trigger CountyInsert on Lead (after insert)
{
list<sundog_deprm2__Postal_Code__c> PostalCodes = [select  Id, Name,sundog_deprm2__County__c from sundog_deprm2__Postal_Code__c w];

for (Lead lead : Trigger.new) {

County__c=lead.County_c;



}
}