• #23077
     pawan makkar #490
    Forcetalks

    Help needed on a Salesforce Trigger manipulating Contact Object

    Help needed on below Salesforce Trigger

    1) Make two DateTime fields on contact object.
    LastTaskCreatedTime
    LastEmailSentTime

    2) Whenever a task is created on Contact LastTaskCreatedTime field should be updated.

    3) Whenever you send an email LastEmailSentTime field should be updated.

     

    #23125
    Salesforce | Charan Tej Charan Tej #569
    Forcetalks

    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;

    }

Viewing 2 posts - 1 through 2 (of 2 total)

Please to reply to this topic.

CONTACT US

We're not around right now. But you can send us an email and we'll get back to you, asap.

Sending

About Us

Forcetalks is a Salesforce collaboration platform for coders & developers, geeks & nerds, consultants & business heads, admins & architects, managers & marketers and of course the business owners. A community where you can learn from, where you can contribute to. For you. For Salesforce. Read More...

Copyright 2019 Forcetalks. All Right Reserved.

Log in with your credentials

or    

Forgot your details?