You need to sign in to do that
Don't have an account?
Trying to assign cases generated by a portal user to another portal user
Hi there,
I am trying to assign cases generated by a portal user (from child account) to another portal user (from parent account).
From what I have read in these boards, changing ownership of cases is different from changing ownership of any other type of record (standard or custom).
BTW, I am not a pro by any means but slowly getting confident at coding triggers.
Any help will be appreciated.
Cheers
This is the trigger:
trigger AssignCasesCreatedByCustPortUsers on Case (before insert) {
List<ID> ParentIdsofCases = new List<ID> (); // List of ParentIds of cases
// From the list of trigger records (in memory), build the list of ParendIds for those cases that need to be assigned to a portal user
for (Case c: trigger.new){
if (c.account.parentid!= null){
ParentIdsofCases.add (c.account.parentid);
}
}
// Retrieve the list of users that are associated with the parentIds
List<Case> UpdatedCases = new List<Case> ();
List<user> UsersofParentIds = [Select id,contact.accountid From User Where contact.accountid IN:ParentIdsofCases];
//for (List<user> U: [Select id,contact.accountid From User Where contact.accountid IN:ParentIdsofCases])
for (Case C:Trigger.new){
for (User U:UsersofParentIds) {
If(c.account.parentid == u.contact.accountid){
// assign case to user
Case CaseToUpdate = C;
CaseToUpdate.ownerid = u.id;
UpdatedCases.add(CaseToUpdate);
}
}
}
update UpdatedCases;
}