function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
gringoesegringoese 

Trigger email alert when new ideaComment added

I am trying to create a trigger that sends an Email Alert (or just an email though Apex code) to the original Idea poster whenever a comment is left for their idea. In looking through the Apex documentation, I noticed it says you can only define triggers for top-level standard objects, but not for standard child objects. When I try to do something like this:

 

 

trigger commentEmail on IdeaComment (after insert) {
// send email code here
}

 

I get "Error: Compile Error: SObject type does not allow triggers: IdeaComment at line 1 column 25". Can anyone point in the right direction to get around this? 

 

 

 

ScoobieScoobie

Any reason why you cannot just use a workflow for this?

 

You can specify the workflow to fire whenever the record is created or updated (I am assuming a comment counts as an update but I am not 100% certain). Then you can fire the email to the record creator using standard workflow actions.

 

edit

 

I think you can say in the rule criteria:

 

Last Commented Date equals today().

 

This should cause the workflow to fire whenever a comment is added

Martin_DeloitteMartin_Deloitte

Maybe a little bit late but we are firing workflow on Idea when a comment is being posted using the following criterias:

  1. Last Idea Comment equals " "
  2. Number of comments greater than 0

Then the workflow rule sends an email to the Idea Creator.

 

Regards,

Ron HessRon Hess

It appears that the idea trigger fires when comments are added, the field that changes on the idea is 

LastCommentDate

 

so you could use this to inspect comments on an idea.  it's not exactly a trigger on idea comment but is useful

rajibnandirajibnandi

can any ont tell me how to trigger email alert when new idea is promoted to 20 or 30 points??

Glenn WeinsteinGlenn Weinstein

Amazingly, Salesforce Ideas still has no feature allowing idea submitters, previous voters, or previous commenters to receive email notifications of future comments.  

 

I took a shot at writing a trigger for this, but ran into a roadblock - the Idea.Comments collection seems to come back empty, even though Ideas.numComments increments.  Code snippet:

 

trigger NotifyAboutNewComment on Idea (after update) {
  Idea i = Trigger.new[0];
  if (i.numComments > 0) {
    System.debug('Idea Comments ==> ' + i.Comments);
  }
}

 

Surprisingly, after you create an idea and post the first comment, you'll see numComments = 1, but the Comments collection is empty, even though it's an "after update" trigger.

 

Any suggestions on why this is happening?

benito camelabenito camela

This should work:

 

trigger myIdeas on Idea (after update) {
    
    if(Trigger.isAfter){
        for (Idea i : Trigger.new) {
            if(i.LastCommentDate > i.LastModifiedDate)
                    System.debug('-------------------------------------------send comment email');
        }
    }
    
}

 

Glenn WeinsteinGlenn Weinstein

Thanks Benito, but your code doesn't address the issue I noted, which is that the Comments collection won't have the latest comment record in it.  So you can't insert it in the email, which defeats the purpose of the trigger.