Activity Forums Salesforce® Discussions Help needed on a Salesforce Trigger manipulating Contact Object

  • Charan Tej

    Member
    January 2, 2018 at 8:22 am

    Whenever you send an email, you need to create an activity under that record. This helps you in tracking the last email sent for that record.

    Trigger should be developed on Task.

    trigger TaskTrg on Task (after insert) {

    List<Contact> lstCons = new List<Contact>();
    for(Task tObj : trigger.new){
    if(tobj.whatId != null && string.valueof(tobj.whatId).startswith('003')){
    Contact con = new Contact(Id=tObj.whatId);
    if(tObj.subject.contains('Email')){
    con.LastEmailSentTime__c = System.now();
    }

    con.LastTaskCreatedTime__c = System.now();
    lstCons.add(con);
    }
    }

    if(!lstCons.isEmpty())
    update lstCons;

    }

Log In to reply.

Popular Salesforce Blogs

Popular Salesforce Videos