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
Sai KethuSai Kethu 

Update Recurring event Owner through trigger

Hi  All,

 

 

          Im Facing an issue while updating the Event records owner change. Below is the error im getting 

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

 

Here is my Query in the trigger,

 

' SELECT Id, OwnerId,Status__c FROM events where  RecurrenceActivityId != null  and IsRecurrence = true '

 

I think there should be mistake in the query.

 

Please help me with the issue

Best Answer chosen by Sai Kethu
TrinayTrinay

HI SaiKethu,

 

     we can't perform the bulk/batch process for recurrence task and recurrence event through the trigger.

 

Refer the following board link, it have the information provided by salesforce support:

 

http://boards.developerforce.com/t5/Apex-Code-Development/UNSUPPORTED-APEX-TRIGGER-OPERATION/td-p/164277

All Answers

Sai KethuSai Kethu

Hi Prakash

 

            Thanks for the reply, actually I have already been though the post, i have modified the query according to it, But the problem is with the recurring events update. Im still facing the same error.

 

Can u pla help me around.

 

If u want i ll post my complete Trigger.........

 

 

TrinayTrinay

Hi,

 

    Please post your full trigger, then i will try to find out the problem in your trigger. 

Sai KethuSai Kethu

Hi Trinay

 

please trigger and its helper class are as below  :   

 

Trigger:

 

trigger Account_After_Update on Account (after update) {

id CurrentuserProfile = UserInfo.getProfileId();
String UserProfileName = [select name from profile where id=:CurrentuserProfile limit 1].name;

Set<Id> accountIds = new Set<Id>(); //This set is used to fetch Account Ids
Map<Id, String> newOwnerIdsMap = new Map<Id, String>();//Map to fetch New Owner Ids aginst Acoount Id's

accountIds.clear();
for (Account a : Trigger.new) {
system.debug('a.OwnerId$$$'+a.OwnerId);
//Condition for processing the trigger
if (a.OwnerId != Trigger.oldMap.get(a.Id).OwnerId  ) ) {
newOwnerIdsMap.put(a.Id, a.OwnerId);
accountIds.add(a.Id);
system.debug('a.Id$$$'+a.id);
}
}

Account_Triggers classobject =New Account_Triggers();
classobject.AccRltdObjOwnChangeMethod(accountIds,newOwnerIdsMap);


}

 

 

 

Helper Class Method:

 

public void AccRltdObjOwnChangeMethod (Set<Id> accountIds, Map<Id, String> newOwnerIdsMap){


if (!accountIds.isEmpty()) {
//SOQL to get Contact,Contacts, Open Activities and Opportunities for all updated Accounts
for (Account act : [SELECT Id, (SELECT Id, OwnerId FROM Contacts), (SELECT Id, OwnerId FROM Contracts),(SELECT Id, OwnerId FROM Opportunities),(SELECT Id, OwnerId,Status__c FROM events where isrecurrence = true and RecurrenceActivityID 1= null),(SELECT Id, OwnerId,Status FROM tasks) FROM Account WHERE Id in :accountIds]) {

//Updating Contact Owner with the Accounts New Ownerrelated to the Account
for (Contact c : act.Contacts ) {
c.OwnerId=newOwnerIdsMap.get(act.id);
listContactObj.add(c);
}

//Updating Contract Owner with the Accounts New Owner related to the Account
for (Contract c : act.Contracts) {
c.OwnerId=newOwnerIdsMap.get(act.id);
listContractObj.add(c);

}
//Updating Opportunity Owner with the Accounts New Owner related to the Account
for (Opportunity o : act.Opportunities) { //for all opportunities
o.OwnerId =newOwnerIdsMap.get(act.id);
listOpportunityObj.add(o);
}

//Updating Open Tasks Owner with the Accounts New Owner related to the Account
for (task t : act.tasks) {
if(t.status=='Open' || t.status == 'Scheduled'){
t.OwnerId =newOwnerIdsMap.get(act.id);
listTaskObj.add(t);
}
}
//Updating Open Events Owner with the Accounts New Owner related to the Account
for (Event e : act.events) {

if(e.status__c=='Pending' || e.status__c == 'Scheduled'){
e.OwnerId =newOwnerIdsMap.get(act.id);
listEventObj.add(e);
}
}

System.debug('$$$$$Events List'+listEventObj);
}

try {
update listContactObj;
update listContractObj;
update listOpportunityObj;
update listTaskObj;
update listEventObj;
}

catch(Exception e) { //catch errors
}
}

Im Facing an error while trying to update and the error is "Apex Event trigger cannot handle batch operations on recurring events."

TrinayTrinay

HI SaiKethu,

 

     we can't perform the bulk/batch process for recurrence task and recurrence event through the trigger.

 

Refer the following board link, it have the information provided by salesforce support:

 

http://boards.developerforce.com/t5/Apex-Code-Development/UNSUPPORTED-APEX-TRIGGER-OPERATION/td-p/164277

This was selected as the best answer