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
akkkakkk 

how to write a trigger after insert the account records create Task after that send email ?

Hi All,

how to write a Trigger after insert the account Records create Task and send email .


Thanks
akkk
ShirishaShirisha (Salesforce Developers) 
Hi,

Greetings!

Please refer the sample code to create the trigger to insert the task and send email notifications and make changes according to your requirement.

https://developer.salesforce.com/forums/?id=906F0000000B3tVIAS

Kindly mark it as best answer if it helps so that it can help others in the future.

Warm Regards,
Shirisha Pathuri
Prosenjit Sarkar 7Prosenjit Sarkar 7
Hi akkk, 

If there is no existing trigger or there os no specific reason to create/update a trigger for Account object, you can utilize Process Builderm which will be more easier and quick. 

Regards, 
Prosenjit
akkkakkk
Hi Prosenjit ,

I dont like Process builder . how to send after insert Account Create Task and send the eamil .

Thanks
akkk
Malika Pathak 9Malika Pathak 9

Hi akkk,

Please find the solution

public static void taskAndMail(List<Account> accList){
        for(Account acc:accList){
            Task taskObj=new Task();
            taskObj.WhatId=acc.Id;
            taskObj.Status='Success';
            taskObj.Priority='high';
            insert taskObj;
            Messaging.SingleEmailMessage producerEmail = new Messaging.SingleEmailMessage();
            producerEmail.setToAddresses(new string[]{'abc@gmail.com'});//insert toaddress email
            producerEmail.setCcAddresses(new string[]{'abs@gmail.com'});//insert ccaddress email
            String htmlBody = 'Hi there!';
            producerEmail.setHtmlBody(htmlBody);
            producerEmail.setUseSignature(false);
            Messaging.sendEmail(new Messaging.SingleEmailMessage[] { producerEmail });
        }
    }
If you find this solution is helpful for you please mark the best answer