You need to sign in to do that
Don't have an account?
Harshavardhan Reddy 29
hi can you please check this trigger is correct to update case owner id with account owner id
trigger CaseOwnerChangeTrigger on Case (before insert,before update)
{
Map<ID, Account> AccownerIds = new Map<ID, Account>();
set<id> accID = new set<id>();
for(Case cn : Trigger.new)
{
if(cn.AccountID!=null)
{
system.debug(cn.AccountID);
accID.add(cn.AccountID);
}
}
for(Account an : [select id,ownerid from account where id IN:accID])
{
AccownerIds.put(an.id,an.ownerid);
}
for(case cb : Trigger.new)
{
if(AccownerIds.containsKey(cb.AccountID))
{
cb.ownerID = AccownerIds.get(cb.AccountID);
}
}
}
{
Map<ID, Account> AccownerIds = new Map<ID, Account>();
set<id> accID = new set<id>();
for(Case cn : Trigger.new)
{
if(cn.AccountID!=null)
{
system.debug(cn.AccountID);
accID.add(cn.AccountID);
}
}
for(Account an : [select id,ownerid from account where id IN:accID])
{
AccownerIds.put(an.id,an.ownerid);
}
for(case cb : Trigger.new)
{
if(AccownerIds.containsKey(cb.AccountID))
{
cb.ownerID = AccownerIds.get(cb.AccountID);
}
}
}
You can use below code to accomplish your task. Let me know if you need more help.
Regards
Naveen