You need to sign in to do that
Don't have an account?
bathy
Recurring event creating an error on apex trigger
Hi all,
I have developed an apex trigger to create a custom object record same like an event when an event is created and used workflow rule on that custom object to send an email alert. because events doesn't support workflow emails.
This trigger is getting an error while creating a recurring event.
I am posting my apex trigger and screen shot of my error message. Please have alook and let me know what could be wrong.
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',
Record_Id__c = newEvent.Id,
Record_Type__c = NewEvent.RecordTypeId,
Start__c = newEvent.StartDateTime,
Assigned_to__c = newEvent.OwnerId,
Created_by__c = newEvent.CreatedById,
Opportunity_Link__c = 'https://superannuationproperty.my.salesforce.com/' + newEvent.WhatId,
Appointment_Successful__c = newEvent.Appointment_Successful__c,
Appointment_Unsuccessful__c = newEvent.Appointment_Unsuccessful__c,
Related_to__c = newEvent.WhatId,
Location__c = newEvent.Location,
End__c = newEvent.EndDateTime,
Description__c = newEvent.Description,
Subject__c = newEvent.Subject,
Detail_link__c = 'https://superannuationproperty.my.salesforce.com/' + newEvent.Id ));
insert t1;
}
}
What I understand is that becuase I haven't selected any opportunity or contact it is giving me error. Is there any way to avoid this for recurring events or any other ideas welcome.
Thanks
I have developed an apex trigger to create a custom object record same like an event when an event is created and used workflow rule on that custom object to send an email alert. because events doesn't support workflow emails.
This trigger is getting an error while creating a recurring event.
I am posting my apex trigger and screen shot of my error message. Please have alook and let me know what could be wrong.
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',
Record_Id__c = newEvent.Id,
Record_Type__c = NewEvent.RecordTypeId,
Start__c = newEvent.StartDateTime,
Assigned_to__c = newEvent.OwnerId,
Created_by__c = newEvent.CreatedById,
Opportunity_Link__c = 'https://superannuationproperty.my.salesforce.com/' + newEvent.WhatId,
Appointment_Successful__c = newEvent.Appointment_Successful__c,
Appointment_Unsuccessful__c = newEvent.Appointment_Unsuccessful__c,
Related_to__c = newEvent.WhatId,
Location__c = newEvent.Location,
End__c = newEvent.EndDateTime,
Description__c = newEvent.Description,
Subject__c = newEvent.Subject,
Detail_link__c = 'https://superannuationproperty.my.salesforce.com/' + newEvent.Id ));
insert t1;
}
}
What I understand is that becuase I haven't selected any opportunity or contact it is giving me error. Is there any way to avoid this for recurring events or any other ideas welcome.
Thanks
All Answers
Not sure why you are getting this error but you certainly should put your insert t1 outside of the loop.
Regards
Don't forget to mark your thread as 'SOLVED' with the answer that best helps you.
Can you try this
Shaijan
Shaijan