I'm trying to implement locking in sake of not having duplicates. The problem is it works only with this line System.debug(LoggingLevel.DEBUG, 'duplicateCallLog.size() == 0 - '+ duplicateCallLog.size());. It sounds like System.debug call guarantees that result of insert will be available in other instances of controllers. Is there any procedure in APEX aka commit or saveChanges that grants data in database? Or there any other locking patterns in APEX?
List<CallLog__c> duplicateCallLog = [SELECT Id FROM CallLog__c WHERE SessionID__c = :sessionId ORDER BY CreatedDate DESC NULLS LAST LIMIT 1];
if(duplicateCallLog.size() == 0)
{
System.debug(LoggingLevel.DEBUG, 'duplicateCallLog.size() == 0 - '+ duplicateCallLog.size());
insert newCallLog;
newCallLog = [SELECT Id FROM CallLog__c WHERE SessionID__c = :sessionId ORDER BY CreatedDate DESC NULLS LAST LIMIT 1];
callLogId = newCallLog.Id;
}
else{
System.debug(LoggingLevel.DEBUG, 'duplicateCallLog.size() != 0 - '+ duplicateCallLog.size());
callLogId = null;
}