You need to sign in to do that
Don't have an account?
jishan roy
Account owner name should same as Opportunity owner name when user is change.
This is my trigger:
Whats wrong in this trigger please help me out of this problem.
code:
trigger oppOwnerTrigger on Opportunity (after insert) {
set<id> setAccountId = new set<id>();
list<Opportunity> oppolist = new list<Opportunity>();
for(Opportunity opp: trigger.new){
setAccountId.add(opp.AccountId);
}
list<Account> acclist=[select id, Name, (select id ,Owner.Name from opportunities) from account where Name != 'null'];
for (Opportunity op:trigger.new){
for(Account accc : acclist){
op.Name = accc.Owner.Name;
system.debug('Account' + accc);
oppolist.add(op);
}
}
insert oppolist;
}
thanks in advance.
Whats wrong in this trigger please help me out of this problem.
code:
trigger oppOwnerTrigger on Opportunity (after insert) {
set<id> setAccountId = new set<id>();
list<Opportunity> oppolist = new list<Opportunity>();
for(Opportunity opp: trigger.new){
setAccountId.add(opp.AccountId);
}
list<Account> acclist=[select id, Name, (select id ,Owner.Name from opportunities) from account where Name != 'null'];
for (Opportunity op:trigger.new){
for(Account accc : acclist){
op.Name = accc.Owner.Name;
system.debug('Account' + accc);
oppolist.add(op);
}
}
insert oppolist;
}
thanks in advance.
try with below code.
If this helps, Please mark it as best answer.
Thanks!!
All Answers
can you confirm the below scenario?
When ever Account owner changes then related opportunity owner change or whenever opportunity owner changes then related account owner should change?
Thanks!!
try with below code.
If this helps, Please mark it as best answer.
Thanks!!
thankyou for helping