You need to sign in to do that
Don't have an account?
jishan roy
how to create helper and handler in this trigger
I want to create helper and handler of this trigger:
trigger oppOwnerTrigger on Opportunity (before insert,before update) {
set<id> setAccountId = new set<id>();
for(Opportunity opp: trigger.new){
if(opp.AccountId !=Null){
setAccountId.add(opp.AccountId);
}
}
Map<id,Account> mappaccidwithvalues = new map<id,Account>();
for(Account acc:[select id,ownerid from Account where id=:setAccountId]){
mappaccidwithvalues.put(acc.id,acc);
}
for (Opportunity op:trigger.new){
if(mappaccidwithvalues.containskey(op.accountid)){
op.ownerId = mappaccidwithvalues.get(op.accountid).ownerid;
}
}
}
trigger oppOwnerTrigger on Opportunity (before insert,before update) {
set<id> setAccountId = new set<id>();
for(Opportunity opp: trigger.new){
if(opp.AccountId !=Null){
setAccountId.add(opp.AccountId);
}
}
Map<id,Account> mappaccidwithvalues = new map<id,Account>();
for(Account acc:[select id,ownerid from Account where id=:setAccountId]){
mappaccidwithvalues.put(acc.id,acc);
}
for (Opportunity op:trigger.new){
if(mappaccidwithvalues.containskey(op.accountid)){
op.ownerId = mappaccidwithvalues.get(op.accountid).ownerid;
}
}
}
The trigger will be as below.
Handler:
Let me know if you face any issues.
If this solution helps, Please mark it as best answer.
Thanks,
All Answers
The trigger will be as below.
Handler:
Let me know if you face any issues.
If this solution helps, Please mark it as best answer.
Thanks,
I will recommend you below url that's will sharp you concept and you can do your self
https://www.mirketa.com/salesforce-developer-guide-use-of-helperhandler-class-to-manage-trigger-execution/
if you need any assistanse, Please let me know!!
Kindly mark my solution as the best answer if it helps you.
Thanks
Mukesh