You need to sign in to do that
Don't have an account?
[Lindsey Kiken]
Apex Trigger Not Firing Correctly
I have a Case trigger that is built to automatically add the ContactId on the Case into the Case Team after insert. Unfortunately, the trigger is firing, not generating an error, and not adding the ContactId to the Team.
Please see the code below:
The ContactId is a required value within the Support Case record type and a value is supplied during each test. I ran a debug test on Apex Code (Debug), but no errors were provided.
Thoughts on what I am missing?
Please see the code below:
trigger CaseTeamMember_Requester_Insert on Case (after insert) { CaseTeamRole role = [select Name from CaseTeamRole where Name = 'Requester' LIMIT 1]; Map<Id, CaseTeamMember> membersToAdd = new Map<Id, CaseTeamMember>(); List<Case> cases = [Select Id,OwnerId,ContactId,RecordTypeId,RecordType.Name from Case where id IN :Trigger.newMap.keySet()]; for (Case c : cases) { if (c.RecordType.Name == 'Support Case') { membersToAdd.put(c.Id, new CaseTeamMember( TeamRoleId = role.Id, ParentId = c.Id, MemberId = c.ContactId ) ); if (!membersToAdd.isEmpty()) { insert membersToAdd.values(); } } } }
The ContactId is a required value within the Support Case record type and a value is supplied during each test. I ran a debug test on Apex Code (Debug), but no errors were provided.
Thoughts on what I am missing?
Please get the below trigger and also enable the debug.
Please do let me know if it helps you.
Regrads,
Mahesh
Thank you for your advice. When I reran the debug with the updated code, the following actions took place:
Thoughts?
Cheers,
Lindsey
I would like to ask you how are you testing it.
You should test it by creating a case by going to Case Tab with the Record Type as 'Support Case'.
To enable the debug, go to Setup --> Monitor --> Debug --> Add your USer Name by clicking on New. Paste the full Trigger execution from the debug.
Regards,
Mahesh