You need to sign in to do that
Don't have an account?
bathy
Apex trigger to update an unrelated custom object record
Hi All,
Since standard salesforce workflow doesn't allow to create eail alerts on events, I have created a custom object named task1__c and created task1 with an Apex trigger to send email alert when an event is created.
Now a new requirement has come up to send an email 2 days after the event is updated.
I am trying to modify the trigger to update the custom object and then use time based workflow on the custom object for email alert. here is my trigger to create new reords. I need help in modifying this trigger to update the custom object records
trigger createtask on Event (after insert) {
List<Task1__c> t1 = new List<Task1__c>();
for (Event newEvent: Trigger.New)
{
t1.add (new Task1__c(
Name = 'New PD',
(text field on task1) Record_Id__c = newEvent.Id,
(text field ontask1)Record_Type__c = NewEvent.RecordTypeId,
Start__c = newEvent.StartDateTime,
Assigned_to__c = newEvent.OwnerId,
Appointment_successful__c = newEvent.Appointment_Successful__c,//a custom tik box on events
Location__c = newEvent.Location,
End__c = newEvent.EndDateTime,
Description__c = newEvent.Description,
Subject__c = newEvent.Subject,
Detail_link__c = 'https://mydomian.my.salesforce.com/' + newEvent.Id )); // to inlcude this detail link in the email alert
}
insert t1;
}
when the user ticks the box Appointment successful an email alert must be generated.
since this is after insert trigger updates on events will not be mapped into custo ibject task1.
please help me to create an update trigger. I am not too sure how to create an update trigger for an unrelated custom object.
your prompt response is greatly appreciated.
thanks in advance.
Since standard salesforce workflow doesn't allow to create eail alerts on events, I have created a custom object named task1__c and created task1 with an Apex trigger to send email alert when an event is created.
Now a new requirement has come up to send an email 2 days after the event is updated.
I am trying to modify the trigger to update the custom object and then use time based workflow on the custom object for email alert. here is my trigger to create new reords. I need help in modifying this trigger to update the custom object records
trigger createtask on Event (after insert) {
List<Task1__c> t1 = new List<Task1__c>();
for (Event newEvent: Trigger.New)
{
t1.add (new Task1__c(
Name = 'New PD',
(text field on task1) Record_Id__c = newEvent.Id,
(text field ontask1)Record_Type__c = NewEvent.RecordTypeId,
Start__c = newEvent.StartDateTime,
Assigned_to__c = newEvent.OwnerId,
Appointment_successful__c = newEvent.Appointment_Successful__c,//a custom tik box on events
Location__c = newEvent.Location,
End__c = newEvent.EndDateTime,
Description__c = newEvent.Description,
Subject__c = newEvent.Subject,
Detail_link__c = 'https://mydomian.my.salesforce.com/' + newEvent.Id )); // to inlcude this detail link in the email alert
}
insert t1;
}
when the user ticks the box Appointment successful an email alert must be generated.
since this is after insert trigger updates on events will not be mapped into custo ibject task1.
please help me to create an update trigger. I am not too sure how to create an update trigger for an unrelated custom object.
your prompt response is greatly appreciated.
thanks in advance.
Try the code below. and dont shy to let me know in case of any issues.
Thanks
All Answers
http://writeforce.blogspot.com/2012/10/sending-email-notification-when.html
for update trigger, try a code like this :
Please bear with me for any syntax errors, i just wrote this code on fly.
Thanks
R G
I am posting the error here can you please correct?
replace that line with lines below
Let me know in case of any issues.
Sorry if I am annoying you. I am completely new to Triggers. Another syntax error has been generated. Please help
Try the code below. and dont shy to let me know in case of any issues.
Thanks
Your code worked very well. thank you so much. Can you provide the test class for this Please?
Thanks,
Thanks for your help. I was able to figure out the test class.
thanks for your help