You need to sign in to do that
Don't have an account?
Skottyp
Trigger won't fire with DataLoader
Hey Team,
My trigger works correctly when changing one record but when I use the data loader it is only assigning 1 sales rep for all the records. I have seen others that have had this same issue and it appears to be something with the mapping, but after a long time of comparing answers in other posts I'm not seeing my error. Please let me know where I am going wrong.
My trigger works correctly when changing one record but when I use the data loader it is only assigning 1 sales rep for all the records. I have seen others that have had this same issue and it appears to be something with the mapping, but after a long time of comparing answers in other posts I'm not seeing my error. Please let me know where I am going wrong.
trigger AssignDistSales1 on Distributor_Sales__c ( before insert, before update) { //get set of 3 digit zips from Distributor Sales to be inserted or updated Set<String> ZIP = new Set<String>(); for(Distributor_Sales__c distsales : Trigger.new){ if(distsales.X3_Digit_Zip__c != null){ ZIP.add(distsales.X3_Digit_Zip__c); } } //list of territories needed to map to Distributor Sales List<Territory__c> potentialTerr = [SELECT X3_Digit_Zip__c, Sales_Rep_for_Later_Assignment__c FROM Territory__c WHERE X3_Digit_Zip__c in :ZIP]; //map that lets me search for territories by their zip Map<String,Territory__c> DistToTerrMap = new Map<String, Territory__c>(); for (Territory__c t: potentialTerr) { DistToTerrMap.put(t.X3_Digit_Zip__c, t); //match the distributor sales 3 digit zip territory by 3 digit zip for(Distributor_Sales__c distsales : Trigger.new){ distsales.Sales_Rep_for_Later_Assignment__c = DistToTerrMap.get(t.X3_Digit_Zip__c).Sales_Rep_for_Later_Assignment__c; } } }
All Answers
Can you try moving the ending parenthesis from line 23 to line 18 and see if that works?
Error: Compile Error: Variable does not exist: t.X3_Digit_Zip__c at line 21 column 73
instead of t.X3_Digit_Zip__c use distsales.X3_Digit_Zip__c
AssignDistSales1: execution of BeforeInsert
caused by: System.NullPointerException: Attempt to de-reference a null object
Trigger.AssignDistSales1: line 21, column 1
It seems like there is something wrong with my initial loop as I am trying to import 60 unique records with 60 unique zip codes, but the debug log only shows that it runs the loop 9 times. Any ideas?
Here is all I get from this:
Full trigger is listed above!
Thanks
And here are my results: