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
SeAlVaSeAlVa 

Problem with SELECT FOR UPDATE in Batch

Hello, 

I have a couple of batches that are taking elements from an object that we use as a queue of integration.

the problem is that sometimes they overlap, and I'm getting ENTITY_IS_DELETED.

I decided to add a
 
Queue__c lock;
try{
    lock = [SELECT Id FROM Queue__c WHERE ID = :theProcessingElement FOR UPDATE];
} catch (Exception e){
    return;
}

// rest of the logic

delete lock;

But I'm still getting a lot of ENTITY_IS_DELETED exceptions

Any ideas?

(I did in all batches)

Thank you in Advance
Kind Regards
Sagar PareekSagar Pareek
Have you tried removing FOR UPDATE?
SeAlVaSeAlVa
Yes, I tried, it was my first attempt.
Then I tried with FOR UPDATE and it did not get better.