• Noah DiPasquale
  • NEWBIE
  • 0 Points
  • Member since 2018

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 0
    Questions
  • 2
    Replies
hello i am writting a trigger to send mail. i am having two objects one is custom and one is contact. on custom object there is lookup relationship with contact. means from custom object we can choose contact. contact will be having email as a mandatory field. when i will choose contact from custom object(Sent feedback) using lookup field then mail will be sent to email address of that contact. can you help me with this?? this is my code. i am not getting mail.

trigger SentFbtrigger on Sent_Feedback__c (after insert) {
    
//Create a master list to hold the emails we'll send

   List<Messaging.SingleEmailMessage> mails = new List<Messaging.SingleEmailMessage>();
    for(Sent_Feedback__c s : Trigger.new) {
    if(s.Contact__r.Email != null && s.Contact__r.Name != null) {
       
        //Create a new Email
      Messaging.SingleEmailMessage mail = new Messaging.SingleEmailMessage();
    
      //Set list of people who should get the email
      List<String> sendTo = new List<String>();
      sendTo.add(s.Contact__r.Email);
      mail.setToAddresses(sendTo);
        mail.setTargetObjectId(s.Contact__r.Id);
        
         //Set who the email is sent from
       mail.setReplyTo('james12@ror.com');
      mail.setSenderDisplayName('James R');
    
    
      // Set email contents - you can use variables!
      mail.setSubject('Subject Content');
      String body = 'Dear ' + s.Contact__r.FirstName + ', ';
      body += 'Email Body';
      
      mail.setHtmlBody(body);
    
      //Add your email to the master list
      mails.add(mail);
    }
  }
  // Send all emails in the master list
  Messaging.sendEmail(mails);
}

I have a custom object called Observation Summary (Observation_Summary__c), and within that object I have a field called Date of Assessment (Date_of_Assessment__c). I would like to create a trigger that does the following:

 

Whenever an email is sent from the Observation Summary record, and that email's subject begins with "Observation feedback", the Date of Assessment field on the Observation Summary should update to become the date that the email was sent.

 

Is this possible? Thanks for your help!