0

I have a batch process that updates the WhoId field of Task records. When this batch process executes, I am currently getting the following error:

Update failed. First exception on row 0 with id 00T0n000003j9xABCW; first error: INVALID_CROSS_REFERENCE_KEY, Updating the whoId fields for shared activities is not allowed.: [WhoId]

Share Activites are already enabled in my Salesforce org. The below is the code snippet:

global class BatchMerge implements Database.Batchable<clsMerge>, Database.Stateful, Database.AllowsCallouts{

global class clsMerge {
        Id WinningId, LosingId;
        String WinningSFDCPartyIdPace, LosingSFDCPartyIdPace;

        //Constructor Override for Contacts
        public clsMerge(String strWinningID, String strLosingId){
            this.WinningID = strWinningID;
            this.LosingId = strLosingId;
        }
}

global void execute(Database.BatchableContext ctx, List<object> scope){

    for(object objScope : scope) {
        clsMerge objMerge = (clsMerge)objScope;                
        String WinningSFDCPartyId = objMerge.WinningId;
        String LosingSFDCPartyId = objMerge.LosingId;
        list<Task> lstTask = new list<Task>();

        for(Task objTask : [Select Id, WhoId From Task where WhoID=:LosingSFDCPartyId]){
            objTask.WhoID = WinningSFDCPartyId;
            lstTask.add(objTask);
        }

        if(lstTask.size() > 0 && lstTask <> null)
            update lstTask;
    }
}
}

How can I resolve the above error? Any help is greatly appreciated!

0

have you tried to update the WhatId instead of WhoId? you might be blocked from updating these by default sharing of WhoId

https://developer.salesforce.com/forums/?id=906F00000008wZlIAI

the link here - depending on what you're object is - you might get more usefulness updating the whatId as the Who Id is typically User or Contact objects - but a whatId you can even use custom objects in.

0

Thank you for responding.

I must update the WhoId, because my batch process is trying to merge two Contact records. The surviving Contact record will get the Task records of the losing Contact record. Thus, I need to update the WhoId of the Task records to the Id of the surviving Contact record.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.