You need to sign in to do that
Don't have an account?
EdL
Simple trigger issue
Hey all,
I'm having a lot of trouble with a trigger I wrote. It works *perfectly* within salesforce, however when I use the Data Loader to get data from a .CSV file, it's like the trigger never even fires.
It's designed to change a relationship by moving some information around. For reference, the Project1 object has a Master-Detail relationship based upon a field called "Project_BEN_Number". When I perform a bulk data load there are no errors given, the rows insert fine. The problem is that the code is never executed, or at least the results are never saved.
Help!
Thanks,
EdL
Trigger Code:
Full disclosure: I use an upsert to load the data, but it still doesn't work even with a regular insert.
Code:
trigger fixType on Resource_Data_Item__c (before insert) { private Resource_Data_Item__c[] ti = Trigger.new; try { string initiative = ti[0].Initiative_Number__c; if(initiative == 'INIT_NA') { ti[0].Initiative_Number__c = ti[0].Project_Name__c; ti[0].Initiative_Name__c = ti[0].Project_Name__c; ti[0].Project_Name__c = ti[0].Task_Name__c; ti[0].Project_Number__c = ti[0].Task_Number__c; string pID = [select ID from Project1__c where Name = :ti[0].Project_Name__c].ID; ti[0].Project__c = pID; } } catch(Exception ex) { ti[0].addError('Insert error: INIT_NA Task ' + ti[0].Task_Name__c + ' does not exist as a project.' + ex.getMessage()); } }
Your Trigger is firing but it's only firing on the first record in your csv file.
You are setting the array with Trigger.new but you are evaluating you logic with the first record in your array. So if the first record passes the test you will update it, and ignore the rest. Or if the first record doesn't pass your test then you will ignore all the records in your insert.
Try this:
Please look at this post for further explanation.
projectName.add(rdi.Project_Name__c);
}