• Benjamin Louis
  • NEWBIE
  • 15 Points
  • Member since 2017

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 1
    Questions
  • 3
    Replies
Hi Guys,

I would kindly like to ask for your help. I am a beginner Apex student, but I am stuck with a trigger :(.
I created a custom field on the case SObject which should serve as a counter.
The trigger should count the string occurences in only outgoing emails and return the # value to this field.
Basically what I want is there are negative words and positive ones (counter should be like positive - negative found words)

This is how far I got:

trigger CaseEmailScore on Case (after insert, after update) {
  
    // Word criteria table,List
    List<String> positiveWords = new List<String>();
    positiveWords.add('Dear');
    positiveWords.add('Kind');
    positiveWords.add('Dreamforce');
    positiveWords.add('Kind regards,');
    positiveWords.add('Best regards,');
    
    List<String> negativeWords = new List<String>();
    negativeWords.add('wtf');
    negativeWords.add('I\'m');
    negativeWords.add('stupid');
    
    for (Case myCase : Trigger.new) {
       
    // Create list of positive emails which are within cases
    List<EmailMessage> caseEmails = [ SELECT  Id,
                                                                               HtmlBody,
                                                                               TextBody,
                                                                               FromAddress,
                                                                               ParentId
                                                               FROM   EmailMessage
                                                            WHERE  ParentId != null];
                                                               //AND  TextBody LIKE :positiveWords]; -> ERROR: TextBody and Html can not be filtered in query call    
        }
    }                                        
    
    //Counting calculations possible .countMatches()


I would really appreciate if you could help, so I can understand and continue learning :).



 
Hi Guys,

I would kindly like to ask for your help. I am a beginner Apex student, but I am stuck with a trigger :(.
I created a custom field on the case SObject which should serve as a counter.
The trigger should count the string occurences in only outgoing emails and return the # value to this field.
Basically what I want is there are negative words and positive ones (counter should be like positive - negative found words)

This is how far I got:

trigger CaseEmailScore on Case (after insert, after update) {
  
    // Word criteria table,List
    List<String> positiveWords = new List<String>();
    positiveWords.add('Dear');
    positiveWords.add('Kind');
    positiveWords.add('Dreamforce');
    positiveWords.add('Kind regards,');
    positiveWords.add('Best regards,');
    
    List<String> negativeWords = new List<String>();
    negativeWords.add('wtf');
    negativeWords.add('I\'m');
    negativeWords.add('stupid');
    
    for (Case myCase : Trigger.new) {
       
    // Create list of positive emails which are within cases
    List<EmailMessage> caseEmails = [ SELECT  Id,
                                                                               HtmlBody,
                                                                               TextBody,
                                                                               FromAddress,
                                                                               ParentId
                                                               FROM   EmailMessage
                                                            WHERE  ParentId != null];
                                                               //AND  TextBody LIKE :positiveWords]; -> ERROR: TextBody and Html can not be filtered in query call    
        }
    }                                        
    
    //Counting calculations possible .countMatches()


I would really appreciate if you could help, so I can understand and continue learning :).