+ Start a Discussion
ap_campionap_campion 

Event Trigger

 I tried to create a before trigger, before update trigger on event that would fetch a field from prospect/contact according to the whoid specified .

But when inserting recurring events through bulk . I get the following error:-

 

"UnexpectedException: Apex Event trigger cannot handle batch operations on recurring events."

 

 

Is there any way to avoid this error ?

UVUV

For recurrence events two records are created..One is series and one is event for that series.Always first record would be your series and rest would be recurrence events..For reference series id is inserted in the RecuurrenceActivityId ..So, for bulk operations deal with first record only..For example if you want to bulk delete then deletion of first record that is series would delete the all recurrence events..Hope this explanation will help you out.

ap_campionap_campion

Thanks for your reply.

I am inserting 2 recurring events through system.debug

Even if the trigger is empty then also there is same error. How can we work only on the series records?

UVUV

As I said first record would be always a series in case of recurrence events..I would suggest you to create a recurring event and then query the Event Id and RecrrenceActivityId to see the result..Its a king of self relationship..

Navatar_DbSupNavatar_DbSup

Hi,

 

You can made changes inside the query like this:

 

List<event> ev=[select id from event where isrecurrence=false];

 

system.debug('@@@@@@@@@@' +ev.size());

 

Now use ev as per your reqirement.

 

Did this answer your question? If not, let me know what didn't work, or if so, please mark it solved. 

ap_campionap_campion

Thanks for your reply. 

Through system log i inserted two recurring events :-

 

------------------------------------------
date dt;
dt=date.parse('12/9/2011');

datetime mydt;
mydt=datetime.now();

event e= new event (
subject='test',
startdatetime=datetime.now(),
enddatetime=datetime.now(),
ISRECURRENCE=true,
RECURRENCESTARTDATETIME= mydt,
RECURRENCEENDDATEONLY=dt,
RECURRENCETIMEZONESIDKEY='America/New_York',
RECURRENCETYPE='RecursEveryWeekday',
RECURRENCEDAYOFWEEKMASK=62
);

list <event> er=new list <event>();
event e1= new event (
subject='test',
startdatetime=datetime.now(),
enddatetime=datetime.now(),
ISRECURRENCE=true,
RECURRENCESTARTDATETIME= mydt,
RECURRENCEENDDATEONLY=dt,
RECURRENCETIMEZONESIDKEY='America/New_York',
RECURRENCETYPE='RecursEveryWeekday',
RECURRENCEDAYOFWEEKMASK=62
);
er.add(e1);
er.add(e);
insert er;

---------------------------------------------------

 

 

Here's the code that i am writing for trigger. But its still giving the same error. 

 

----------------------------------------------------------------------------

trigger TimezoneUpdateEvent on Event (before insert) {

 

 

List ev=[select id from event where id in :trigger.new AND isrecurrence=false ];

system.debug('@@@@@@@@@@' +ev.size());

 

}

-----------------------------------------------------------------------------

questions:-

1. In spite of specifying isrecurrence = false(which means its either a series record or normal event? ) why still the error is coming?

2. What to use in trigger before insert or after insert? I tried both.

3. In the above query,  shouldn't isrecurrence be true because we have to handle only the series records right? 

UVUV

This Sample code works fine-

trigger deleteTask on Lead (after update) 
{
    Lead lead = trigger.new[0];
    List <Event> e1 = new List<Event>(); 
    
    if (trigger.isUpdate)
    {  
        e1 =[select id,subject from Event where Whoid =: lead.id];
        System.debug('--->>>'+e1);

        delete e1[0];
    }
}
ap_campionap_campion

Hi UV,

Thanks for your reply. The above trigger that you wrote is on lead object . The trigger that is giving error is on event. The trigger.new for event trigger will contain all the records , series as well as event recurrence. How do we stop the recurrence events from coming to trigger.new?

 

Please correct if i am wrong. I am kind of beginner.

UVUV

You would have to filter out the records on the basis of RecurrenceActivityId.

Check in query if RecurrenceActivityId=null..Query would be like-

select id,subject,WhatId,WhoID,RecurrenceActivityId from Event where Whoid =:TempId and RecurrenceActivityId=null

apapapap

Thanks for the reply.

I ran the below trigger on task by inserting two recurring tasks through system log. But still its the same thing.In this trigger i am using only the filtered records .

 


trigger AutoCreateFollowUpTasks on task (after insert) {


list <task> aa=[select id,subject,WhatId,WhoID,RecurrenceActivityId from task where id in :trigger.new and RecurrenceActivityId=null];

for(task a :aa)
{
system.debug('FOR LOOP');
}
}

 

This quey would fetch me all the non recurring tasks. Right? But it gives the same exception.

 

 

Ker DeveloperKer Developer

Hello , 

 

I tried your solution by making this inside a for like this : 

 

	for(Event e:trigger.new)
  	{
  		if((e.IsRecurrence ==false && e.RecurrenceActivityId==null) ||(e.IsRecurrence ==true && e.RecurrenceActivityId!=null))
  		{
		  		if
		  		(e.Statut__c == 'Terminé' && e.Statut__c != trigger.oldMap.get(e.id).Statut__c )
		  		{
		  			//|| (e.Visite_realisee__c != trigger.oldMap.get(e.id).Visite_realisee__c && e.Visite_realisee__c == true)){
		  			eventRToUpdate.add(e);
		  		}
		  		if(e.Statut__c != 'Terminé' &&  trigger.oldMap.get(e.id).Statut__c == 'Terminé')
		  		{
		  			//operation inverse
		  			eventPToUpdate.add(e);
		  		}
  		}
  	}

 

But i got always the same error , Any idea? 

sgroversgrover

Sorry I never updated my reply.  We've since removed this code as it started causing issues later in the development cycle.  I'm afraid I don't have an answer for you at the moment.

Ker DeveloperKer Developer

So you still faceing the same problem? or did you find a manner to avoid it? by changing data loader batch size for example?

sgroversgrover

It's been a while, but looking through some old emails, it looks like we changed the batch size to 1.  There were still a couple of errors, but in our case on private events were causing issues, so we just excluded those from the query.  I should also mention that we only needed to run this batch once to update event data for some new features we were implementing.

acousticacoustic
Has anyone figured it out for the trigger (not the data-loader). I'm having the same issue with Tasks when trying to update a lookup field in a trigger.