4

I have the following code:

Administratie__c theAdmin = [SELECT Artikelen_laatst_bijgewerkt_op__c FROM Administratie__c LIMIT 1][0];
theAdmin.Artikelen_laatst_bijgewerkt_op__c = dateTimeOfLastModification;
update theAdmin;

Which leads to the following log lines:

15:54:11.0 (23662906)|SOQL_EXECUTE_BEGIN|[19]|Aggregations:0|SELECT Artikelen_laatst_bijgewerkt_op__c FROM Administratie__c LIMIT 1
15:54:11.0 (26685794)|SOQL_EXECUTE_END|[19]|Rows:1
15:54:11.0 (26718836)|HEAP_ALLOCATE|[19]|Bytes:8
15:54:11.0 (26741000)|HEAP_ALLOCATE|[19]|Bytes:70
15:54:11.0 (26845854)|HEAP_ALLOCATE|[19]|Bytes:8
15:54:11.0 (26894245)|HEAP_ALLOCATE|[19]|Bytes:12
15:54:11.0 (26904321)|VARIABLE_SCOPE_BEGIN|[19]|theAdmin|Administratie__c|true|false
15:54:11.0 (26952408)|VARIABLE_ASSIGNMENT|[19]|theAdmin|{"Artikelen_laatst_bijgewerkt_op__c":"2019-03-28T13:48:14.000Z","Id":"a0G1l000000c12LEAQ"}|0x5dfa991c
15:54:11.0 (26960746)|STATEMENT_EXECUTE|[20]
15:54:11.0 (27028989)|VARIABLE_ASSIGNMENT|[20]|this.Artikelen_laatst_bijgewerkt_op__c|"2019-03-28T14:54:11.963Z"|0x5dfa991c
15:54:11.0 (27035931)|STATEMENT_EXECUTE|[21]
15:54:11.0 (27071056)|HEAP_ALLOCATE|[21]|Bytes:8
15:54:11.0 (27085877)|DML_BEGIN|[21]|Op:Update|Type:Administratie__c|Rows:1
15:54:11.0 (27118984)|HEAP_ALLOCATE|[EXTERNAL]|Bytes:8
15:54:11.0 (55148251)|DML_END|[21]

This suggests that the update was successful. But I also see this at the end of the log:

08:33:30.350 (350869114)|CUMULATIVE_LIMIT_USAGE
08:33:30.350 (350869114)|LIMIT_USAGE_FOR_NS|(default)|
  Number of SOQL queries: 0 out of 200
  Number of query rows: 0 out of 50000
  Number of SOSL queries: 0 out of 20
  Number of DML statements: 0 out of 150
  Number of DML rows: 0 out of 10000
  Maximum CPU time: 0 out of 60000
  Maximum heap size: 0 out of 12000000
  Number of callouts: 0 out of 0
  Number of Email Invocations: 0 out of 10
  Number of future calls: 0 out of 0
  Number of queueable jobs added to the queue: 0 out of 1
  Number of Mobile Apex push calls: 0 out of 10

08:33:30.350 (350869114)|CUMULATIVE_LIMIT_USAGE_END

08:33:30.0 (350916922)|CODE_UNIT_FINISHED|ProductInfoJobViaTalend
08:33:30.0 (352217971)|EXECUTION_FINISHED

And indeed, the record has not been updated. This is part of a batch job. In total I have 23 log files. The above segment is the last part of the last log file. The logfiles do not contain any errors or warnings. But also: all log files show zero activity in their summaries: no SOQL queries, no DML statements, no CPU time. While the details of the log files show all kinds of queries and updates.

The log file summaries even say "Number of callouts: 0 out of 0", while just above it I see lines like "CALLOUT_RESPONSE|[31]|System.HttpResponse[Status=OK, StatusCode=200]". The fact that I get so many log files tells me that 4 callouts were done. Salesforce is doing all kinds of things, but the summaries all say that nothing happened at all.

In my six years of Apex programming, I have not seen this behavior before. Who recognizes this? What am I doing wrong?

  • 1
    Weird. Is it sandbox? and are you getting any error /exception/ – Pranay Jaiswal Mar 28 at 15:50
  • 5
    is this end of your debug or you have some other transaction after this DML? It seems like your transaction is getting rolled back – Himanshu Mar 28 at 15:54
  • Have you tried to use Database.insert instead of the simple and check the result of it (Database.SaveResult)? Similar way like this: List<Database.SaveResult> results = Database.update(theAdmin); for (Database.SaveResult result : results) { if (!result.isSuccess()){ for (Database.Error err : result.getErrors()){ System.debug('Error: '+ err.getStatusCode() + ' ' + err.getMessage()); } } } – Marcell Csiszár Mar 29 at 8:39
  • 2
    @SanderdeJong Try to subscribe for CDC on this item via Streaming Monitor app and you can check maybe when it's rollbacking then. Maybe you can catch some other process and then you will be able to monitor/debug that file. I would subscribe to all apex classes, and the CDC's event time maybe can lead you which class rollbacking your changes. Do you have rollup summary field on that custom object? Have you inactivated all the workflow rules? – Marcell Csiszár Apr 1 at 7:00
  • 1
    trailhead.salesforce.com/en/content/learn/modules/… I forget to include that you need to enable CDC for your Administratie__c object before you can actually check the change events. – Marcell Csiszár Apr 1 at 15:22
1

My source code should have given a clue as to what went wrong, but in hindsight everything makes sense.

The code assumes that only a single Administratie__c record exists. But to my surprise, there were two of them! So the code fails. It updated record A, while I was watching record B.

The log files still don't make sense, though. Records are updated, call-outs are being made, but the log summaries always tell me that nothing has happened.

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.