You need to sign in to do that
Don't have an account?
Trigger help with data loader
Hello apex experts,
I have a field on the account object that updates when the account is edited. When the record is edited individually, the correct value gets written to the field. When I use the data loader . . . One value applies to all records. Here is my trigger, please advise.
trigger Populate_Transfer_Manager on Account (before insert, before Update) {
list<id> aid = new list<id>();
for(account a: trigger.new){
aid.add(a.ownerid);
}
list<user> managers = new list<user>();
managers = [select managerid from user where id in: aid];
set<id> manid = new set<id>();
for(user u: managers){
manid.add(u.managerid);
}
for(account a: trigger.new){
for(id i: manid){
a.transfer_manager__c = i;
}
}
}
Turns out this was a simple task!
trigger Populate_Transfer_Manager on Account (before insert, before Update) {
list<id> aid = new list<id>();
for(account a: trigger.new){
aid.add(a.ownerid);
}
map<id, user> users = new map<id, user>(
[select managerid from user where id in: aid]);
for(account a: trigger.new){
a.Transfer_Manager__c = users.get(a.ownerid).managerid;
}
}
All Answers
Turns out this was a simple task!
trigger Populate_Transfer_Manager on Account (before insert, before Update) {
list<id> aid = new list<id>();
for(account a: trigger.new){
aid.add(a.ownerid);
}
map<id, user> users = new map<id, user>(
[select managerid from user where id in: aid]);
for(account a: trigger.new){
a.Transfer_Manager__c = users.get(a.ownerid).managerid;
}
}
You could do something like this;