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
Arpit Gupta 62Arpit Gupta 62 

When Lead Status Set to 'Working - Contacted ' send email to Client i.e . Lead's Email And add Date to field ‘Date_to_Send_email__c’ i.e today's date.

When Lead Status Set to 'Working - Contacted ' send email to Client i.e . Lead's Email 
    And add Date to field ‘Date_to_Send_email__c’  i.e today's date.
 
Karthikeyan Rajendran 14Karthikeyan Rajendran 14
Hi Arpit

    you can easily achieve this via Process builder. 

In Process Builder
      1. Select "Lead" as the Object.
      2. Choose "When a record is created or edited" in "Start the process"
      3. In Criteria choose "Conditions are met" and then set your conditions as
                 [Lead]Status = Working - Contacted
      4. Select All of the conditions are met (AND)
      5. In immediate Actions Set Email Alert from the Action type
                For email alert - You have to have a email alert created for the Lead object.
      6. In immediate action itself select Update records from the Action Type and choose the field to update and type as Formula
                In value to update set the formula to update date field.

Regards
Karthik
Ajay K DubediAjay K Dubedi
Hi Arpit,
Try this trigger and its handler class:

Trigger:
 
trigger LeadTrigger on Lead (before insert, before update) {
    if((trigger.IsInsert && trigger.IsBefore) || (trigger.IsUpdate && trigger.IsBefore)) {
        LeadTrigger_handler.sendEmailToClient(trigger.new);
    }
}


Handler Class:
 
public class LeadTrigger_handler {
    public static void sendEmailToClient(List<Lead> leadList) {
        try 
        {
            List<String> leadEmailList = new List<String>();
            List<Messaging.SingleEmailMessage> mails =  new List<Messaging.SingleEmailMessage>();
            for(Lead l : leadList) {
                if(l.Status == 'Working - Contacted') {
                    leadEmailList.add(l.Email);
                    l.Date_to_Send_email__c = date.today();
                }
            }
            if(leadEmailList.size() > 0) {
                Messaging.SingleEmailMessage mail = new Messaging.SingleEmailMessage();
                mail.setToAddresses(leadEmailList);
                
                mail.setSubject('Lead Status');
                String body = 'Lead Status is Working - Contacted';
                mail.setHtmlBody(body);
                mails.add(mail);
                Messaging.sendEmail(mails);
            }
        }
        catch(Exception ex)
        {
            System.debug('Exception on Line Number ' + ex.getLineNumber() + ' Message ---- ' + ex.getMessage());
        }
    }
}


I hope you find the above solution helpful. If it does, please mark as Best Answer to help others too.
Thanks,
Ajay Dubedi
Arpit Gupta 62Arpit Gupta 62
thanku sir😃