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
neshnesh 

how to automatically send email Using apex. trigger-.whenever create a new record under A Object

Hi,

i have custom object A.B AND C Object have Lookup relationship with A OBJECT.In A object Have custom field name: delevery template (its a rich text).it is work as a EMAILTEMPLATE....
My task is whenever create a new record under A Object -when select 'B'&'c' custom  field...custom field name: delevery template (its a rich text) section automatically send email to 'B' object emailfield.
here i am use delevery template (its a rich text) section like a plaintext for email..how to automatically send email whenever create a new record under A Object -when select 'B'&'c' custom  field Using apex trigger..
please give your knowledge.

grandmastergrandmaster

I didn't get your question completely. Anyways, I've tried to build up some code for you:

 

trigger yourtriggername on YourObject(before update){


List<Task> tasks = new List<Task>();
List<Messaging.SingleEmailMessage> emails = new List<Messaging.SingleEmailMessage>();
for(YourObject y: Trigger.new)
{
// Write logic for your condition, if it gets satisfied, then invoke the lines below....
tasks.add(new Task(
OwnerId = '' //assign the User Id to whom you wana assign this,
WhoId = y.Id,
ActivityDate = ''; // Set the date
IsReminderSet = false,
Subject = 'Here goes the subject line',
Description = 'Hre goes the body';
}
insert tasks;
}

 

Thanks

gm

grandmastergrandmaster

I didn't get your question completely. Anyways, I've tried to build up some code for you:    

 

trigger yourtriggername on YourObject(before update){


List<Task> tasks = new List<Task>();
List<Messaging.SingleEmailMessage> emails = new List<Messaging.SingleEmailMessage>();
for(YourObject y: Trigger.new)
{
// Write logic for your condition, if it gets satisfied, then invoke the lines below....
tasks.add(new Task(
OwnerId = '' //assign the User Id to whom you wana assign this,
WhoId = y.Id,
ActivityDate = ''; // Set the date
IsReminderSet = false,
Subject = 'Here goes the subject line',
Description = 'Hre goes the body';
}
insert tasks;
}

 

Thanks

gm

Abhi_TripathiAbhi_Tripathi

Here is the simple example of sending email Using trigger, whenever record is inserted or updated.

 

http://abhithetechknight.blogspot.in/2013/10/send-email-using-trigger.html