Baffled by a new record I've added that isn't available to query.
Person__c b = New Person__c(Name='Bob'); insert b; //Returns a valid Id Person_c newRecord = [SELECT Name FROM Person__c WHERE Id=:b.Id LIMIT 1]; //Returns NULL
I figured the insert operation might not have completed, so I tried:
Integer amount; Database.SaveResult sr; amount = [SELECT COUNT() FROM Person__c]; //Returns 3 sObject s = new Person__c (Name='Bob'); sr = Database.insertImmediate(s); if (sr.isSuccess()) System.Debug('Saved!'); //Shows saved amount = [SELECT COUNT() FROM Person__c]; //Returns 3 (expected 4)
Both of the above inserts work, but I can't seem to retrieve the new record within the same function. When I refresh the page, I can see there are now 4 records.
This works in a timely manner as a logged in user or on Dev console. Just not on guest. On guest, there is some sort of delay. The fact that the insert occurs (later) suggests I have the permissions set to Create + the field-level settings.
Am I missing a step such as "reindex" or "Database.refresh()"