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
randombardrandombard 

Send Email if chatter body contains #Tech

Hi All,

 


Trying to work out how to achieve this, so far I have the following but nothing appears to happen.

 

please note where is states emailfgoeshere I usually place an email address, just not in this example.  :-)

 

trigger IncludeTechnicalSuppoer on FeedItem (before insert) {
String oppKeyPrefix = Opportunity.sObjectType.getDescribe().getKeyPrefix();
    for (FeedItem f: trigger.new)
     {
         String parentId = f.parentId;
          //We compare the start of the 'parentID' field to the Opportunity key prefix to
          //restrict the trigger to act on posts made to the Opportunity object.
          if (parentId.startsWith(oppKeyPrefix) &&
              f.Body == '#Tech')
          {           
                //Send message to technical support
               String[] toaddress = new String[]{};
                toaddress.add('emailgoeshere');
                Messaging.SingleEmailMessage mail = new Messaging.SingleEmailMessage();
                mail.setToAddresses(toaddress);
                mail.setsubject('TechnicalMessage');
                mail.saveAsActivity = false;
              
          }
      }
  }

 First question what do I need to do to make this actually send and second question should I really be using a template to send richer content?

 

Thanks

 

R

Best Answer chosen by Admin (Salesforce Developers) 
Vinit_KumarVinit_Kumar

You are missing sendEmail method in your code which is required to send mails.

 

Please put below code after mail.saveActivity=false;

 

Messaging.sendEmail(new Messaging.SingleEmailMessage[] { mail });

 

and it would work.

All Answers

Vinit_KumarVinit_Kumar

You are missing sendEmail method in your code which is required to send mails.

 

Please put below code after mail.saveActivity=false;

 

Messaging.sendEmail(new Messaging.SingleEmailMessage[] { mail });

 

and it would work.

This was selected as the best answer
randombardrandombard

That's brilliant thanks