You need to sign in to do that
Don't have an account?
Adding contacts as case team members
I am using the following APEX trigger to add Contacts automatically to cases that want to be (theres a check box for it) but it is not adding case team members to case. What am I missing here?
trigger CaseTeamAddition on Case (after insert) {
if (Trigger.isAfter){
If (Trigger.isInsert){
CaseTeamRole caseTeamRole = [SELECT Id
FROM CaseTeamRole
WHERE Name = 'Case Update Team'
LIMIT 1];
List<Id> accountIdList = new List<Id>();
For (Case currentCase : Trigger.new){
accountIdList.add(currentCase.AccountId);
}
List<Contact> contactList = [SELECT Id, AccountId
FROM Contact
WHERE AccountId IN : accountIdList
AND Get_Email_Updates__c = true];
List<CaseTeamMember> caseMembersToInsert = new List<CaseTeamMember>();
For (Case currentCase : Trigger.new){
For (Contact currentContact : contactList){
If (currentContact.AccountId == currentCase.AccountId){
CaseTeamMember newMember = new CaseTeamMember(ParentId = currentCase.Id,
MemberId = currentContact.Id,
TeamRoleId = caseTeamRole.Id);
caseMembersToInsert.add(newMember);
}
}
}
if (caseMembersToInsert.size() > 0){
insert caseMembersToInsert;
}
}
}
}
Ended up using the following to add profile into the code in this situation which enabled us to get rid of the errors and have it find people correct
User dbUser = [SELECT Id
FROM User
WHERE Alias = 'dblevins'
LIMIT 1];
List<Case> caseList = [SELECT Id, OwnerId
FROM Case
WHERE Id IN :caseIdList
//AND Type = 'Web'];
AND Owner.Profile.Name = 'Customer Community User'];
for (Case curCase : caseList){
curCase.OwnerId = dbUser.Id;
}
All Answers
The code looks fine to me. There might be field level security issue with the new field Get_Email_Updates__c. Please check this field's permission once. Have you recieved any error in the debug log?
Regards,
Debanjan
Ended up using the following to add profile into the code in this situation which enabled us to get rid of the errors and have it find people correct
User dbUser = [SELECT Id
FROM User
WHERE Alias = 'dblevins'
LIMIT 1];
List<Case> caseList = [SELECT Id, OwnerId
FROM Case
WHERE Id IN :caseIdList
//AND Type = 'Web'];
AND Owner.Profile.Name = 'Customer Community User'];
for (Case curCase : caseList){
curCase.OwnerId = dbUser.Id;
}