You need to sign in to do that
Don't have an account?
CageMMA
Trigger not picking up Parent id's???
Hi:
I am doing a trigger from CaseComment where I went to send out an email to admins when the case owner and case comment owner is the same... but my trigger is not working keeps bringing up null values for the parent..where am i going wrong
trigger TRG_CaseCommentEmailToCaseAssignedTo on CaseComment (after insert,after update) { System.Debug('zitistrue1'); for(CaseComment c : trigger.new) { System.Debug('z2' + c.CreatedById); System.Debug('z3' + c.Parent.Ownerid); System.Debug('z4' + c.Parent.RecordTypeid); if((c.CreatedById == c.Parent.Ownerid && c.Parent.RecordTypeid=='0123000000092K5ZZA')) { CLS_MailerClass.sendMail(c.CommentBody); } } }
Make the following changes to your code:
****Note: Try to change little bit the code. Use the soql queries outside for loop.
trigger TRG_CaseCommentEmailToCaseAssignedTo on CaseComment (after insert,after update)
{
System.Debug('zitistrue1');
for(CaseComment c : trigger.new)
{
System.Debug('z2' + c.CreatedById);
System.Debug('z3' + c.ParentId);
System.Debug('z4' + c.Parent.RecordTypeid);
Case caseOwnerId = [select ownerId from case where Id=:c.ParentId]; //If your query is retrieving more than one row Use the code below
if((c.CreatedById == caseOwnerId.ownerId && c.Parent.RecordTypeid=='0123000000092K5ZZA'))
{
CLS_MailerClass.sendMail(c.CommentBody);
}
}
}
//Use this code if your list is retrieving more than one row
trigger TRG_CaseCommentEmailToCaseAssignedTo on CaseComment (after insert,after update)
{
System.Debug('zitistrue1');
for(CaseComment c : trigger.new)
{
System.Debug('z2' + c.CreatedById);
System.Debug('z3' + c.ParentId);
System.Debug('z4' + c.Parent.RecordTypeid);
Public Id oId {get;set;}
List<Case> caseOwnerId = [select ownerId from case where Id =:c.ParentId];
for(Case cowner : caseOwnerId){
oId = cowner.OwnerId;
}
if((c.CreatedById == oId && c.Parent.RecordTypeid=='0123000000092K5ZZA'))
{
CLS_MailerClass.sendMail(c.CommentBody);
}
}
}
Hope this helps you..............
Accept it as a solution if this resolves your issue
All Answers
CaseComment may be different, but typically, triggers don't have the context for related records, including parent records.
I think you would need to re-query for the Case Fields from Case, put them in a map, and then retrieve them during the loop to test the logic
Make the following changes to your code:
****Note: Try to change little bit the code. Use the soql queries outside for loop.
trigger TRG_CaseCommentEmailToCaseAssignedTo on CaseComment (after insert,after update)
{
System.Debug('zitistrue1');
for(CaseComment c : trigger.new)
{
System.Debug('z2' + c.CreatedById);
System.Debug('z3' + c.ParentId);
System.Debug('z4' + c.Parent.RecordTypeid);
Case caseOwnerId = [select ownerId from case where Id=:c.ParentId]; //If your query is retrieving more than one row Use the code below
if((c.CreatedById == caseOwnerId.ownerId && c.Parent.RecordTypeid=='0123000000092K5ZZA'))
{
CLS_MailerClass.sendMail(c.CommentBody);
}
}
}
//Use this code if your list is retrieving more than one row
trigger TRG_CaseCommentEmailToCaseAssignedTo on CaseComment (after insert,after update)
{
System.Debug('zitistrue1');
for(CaseComment c : trigger.new)
{
System.Debug('z2' + c.CreatedById);
System.Debug('z3' + c.ParentId);
System.Debug('z4' + c.Parent.RecordTypeid);
Public Id oId {get;set;}
List<Case> caseOwnerId = [select ownerId from case where Id =:c.ParentId];
for(Case cowner : caseOwnerId){
oId = cowner.OwnerId;
}
if((c.CreatedById == oId && c.Parent.RecordTypeid=='0123000000092K5ZZA'))
{
CLS_MailerClass.sendMail(c.CommentBody);
}
}
}
Hope this helps you..............
Accept it as a solution if this resolves your issue
That would still break in bulk...
This would work better: