Trigger to create an attachment and attach it along with the record in Salesforce

Sample Trigger:

trigger sendEmail on Employee__c (after insert)  {    
    List<Attachment> listAttachments = new List<Attachment>();
    for(Employee__c e : {   
        Attachment a = new Attachment();
        a.ParentId = e.Id;
        a.Name = e.Name + Date.Today();
        a.ContentType = 'text/plain';
        a.Body = Blob.valueOf(e.Name + ' is added successfully');
    insert listAttachments;


1 comment:

  1. Is it possible to write a trigger to just modify the title of an existing Attachment, as opposed to creating a new one?


Sharing is Caring!!! Share this with your friends!!!

submit to reddit