You need to sign in to do that
Don't have an account?
Nkosilathi Ncube
NULLPOINTER exception help
Hello Community, I have written this trigger to update County field for a particualr postcode, I am getting a NULLPOINTER Exception, please help
trigger TriggerUpdateContact on Contact(before insert, before update) { if(RecursiveTriggerHandler.isFirstTime){ RecursiveTriggerHandler.isFirstTime = false; } // querying all the name and Zipcode from County object List<PostCodes__c> countyList = [select Id, PostCode__c, County__c from PostCodes__c]; Map<String,String > PostCodeMap = new Map<String,String>(); //populating the Map for(PostCodes__c p : countyList ){ PostCodeMap.put(p.PostCode__c,p.County__c); } for (Contact c :Trigger.new){ string postcode2; if (c.MailingPostalCode.length() >= 8) { postcode2 = c.MailingPostalCode.substring(0,4); } else if (c.MailingPostalCode.length() >= 7) { postcode2 = c.MailingPostalCode.substring(0,3); } else { postcode2 = c.MailingPostalCode.substring(0,2); } if(c.MailingPostalCode!= null && PostCodeMap.containsKey(postcode2)) { c.County__c=PostCodeMap.get(postcode2); }else c.County__c = 'Unknown'; }}
All Answers
Please use the below code
Thanks
Anupama