You need to sign in to do that
Don't have an account?
Valentin M
Database.update successful but records are not updated
Hi everyone,
I have the following code which tries to update EmailMessage records based on information from an external service (Mandrill).
The logs don't show any failure, I can even see that the update is successful but when I access the EmailMessage page, the informations are not the ones I see in my logs.
12:32:26.0 (300687341)|STATEMENT_EXECUTE|[169]
12:32:26.0 (300718578)|SYSTEM_METHOD_ENTRY|[169]|Database.update(List<SObject>, Boolean)
12:32:26.0 (300756556)|DML_BEGIN|[169]|Op:Update|Type:EmailMessage|Rows:1
12:32:26.0 (300768393)|LIMIT_USAGE|[169]|DML|1|150
12:32:26.0 (300782678)|LIMIT_USAGE|[169]|DML_ROWS|1|10000
12:32:26.0 (300802113)|HEAP_ALLOCATE|[EXTERNAL]|Bytes:8
12:32:26.0 (327344978)|DML_END|[169]
12:32:26.0 (327450584)|HEAP_ALLOCATE|[EXTERNAL]|Bytes:8
12:32:26.0 (327499262)|HEAP_ALLOCATE|[169]|Bytes:8
12:32:26.0 (327524120)|SYSTEM_METHOD_EXIT|[169]|Database.update(List<SObject>, Boolean)
12:32:26.0 (327536399)|VARIABLE_SCOPE_BEGIN|[169]|results|List<Database.SaveResult>|true|false
12:32:26.0 (327580606)|VARIABLE_ASSIGNMENT|[169]|results|{"s":1,"v":[{"success":true,"id":"02s4XXX"}]}|0x397955cc
12:32:26.0 (327651604)|SYSTEM_METHOD_ENTRY|[170]|List<Database.SaveResult>.iterator()
12:32:26.0 (327776810)|SYSTEM_METHOD_EXIT|[170]|List<Database.SaveResult>.iterator()
12:32:26.0 (327802560)|SYSTEM_METHOD_ENTRY|[170]|system.ListIterator.hasNext()
12:32:26.0 (327816542)|HEAP_ALLOCATE|[170]|Bytes:5
12:32:26.0 (327824335)|SYSTEM_METHOD_EXIT|[170]|system.ListIterator.hasNext()
12:32:26.0 (327938910)|HEAP_ALLOCATE|[170]|Bytes:4
12:32:26.0 (327972391)|VARIABLE_SCOPE_BEGIN|[170]|result|Database.SaveResult|true|false
12:32:26.0 (327990129)|VARIABLE_ASSIGNMENT|[170]|result|{"success":true,"id":"02s4XXX"}|0x3714391c
12:32:26.0 (327994561)|STATEMENT_EXECUTE|[170]
12:32:26.0 (328026370)|STATEMENT_EXECUTE|[171]
12:32:26.0 (328037260)|SYSTEM_METHOD_ENTRY|[170]|system.ListIterator.hasNext()
Does anyone have an idea of what is happening ?
Thanks
I have the following code which tries to update EmailMessage records based on information from an external service (Mandrill).
String mandrillInfoUrl = MandrillConfig.API_URL + MandrillConfig.MESSAGE_INFO_ENDPOINT; for (EmailMessage m : emailMessages) { Map<String, Object> data = queryMandrill(mandrillInfoUrl, m); if (data == null) continue; m.Click_count__c = (Integer) data.get('clicks'); m.Open_count__c = (Integer) data.get('opens'); m.Subject = (String) data.get('subject'); m.Mandrill_status__c = convertMandrillStatus((String) data.get('state')); } List<Database.SaveResult> results = Database.update(emailMessages, false); for (Database.SaveResult result : results) { if (!result.isSuccess()){ for (Database.Error err : result.getErrors()){ System.debug('Error: '+ err.getStatusCode() + ' ' + err.getMessage()); } } }
The logs don't show any failure, I can even see that the update is successful but when I access the EmailMessage page, the informations are not the ones I see in my logs.
12:32:26.0 (300687341)|STATEMENT_EXECUTE|[169]
12:32:26.0 (300718578)|SYSTEM_METHOD_ENTRY|[169]|Database.update(List<SObject>, Boolean)
12:32:26.0 (300756556)|DML_BEGIN|[169]|Op:Update|Type:EmailMessage|Rows:1
12:32:26.0 (300768393)|LIMIT_USAGE|[169]|DML|1|150
12:32:26.0 (300782678)|LIMIT_USAGE|[169]|DML_ROWS|1|10000
12:32:26.0 (300802113)|HEAP_ALLOCATE|[EXTERNAL]|Bytes:8
12:32:26.0 (327344978)|DML_END|[169]
12:32:26.0 (327450584)|HEAP_ALLOCATE|[EXTERNAL]|Bytes:8
12:32:26.0 (327499262)|HEAP_ALLOCATE|[169]|Bytes:8
12:32:26.0 (327524120)|SYSTEM_METHOD_EXIT|[169]|Database.update(List<SObject>, Boolean)
12:32:26.0 (327536399)|VARIABLE_SCOPE_BEGIN|[169]|results|List<Database.SaveResult>|true|false
12:32:26.0 (327580606)|VARIABLE_ASSIGNMENT|[169]|results|{"s":1,"v":[{"success":true,"id":"02s4XXX"}]}|0x397955cc
12:32:26.0 (327651604)|SYSTEM_METHOD_ENTRY|[170]|List<Database.SaveResult>.iterator()
12:32:26.0 (327776810)|SYSTEM_METHOD_EXIT|[170]|List<Database.SaveResult>.iterator()
12:32:26.0 (327802560)|SYSTEM_METHOD_ENTRY|[170]|system.ListIterator.hasNext()
12:32:26.0 (327816542)|HEAP_ALLOCATE|[170]|Bytes:5
12:32:26.0 (327824335)|SYSTEM_METHOD_EXIT|[170]|system.ListIterator.hasNext()
12:32:26.0 (327938910)|HEAP_ALLOCATE|[170]|Bytes:4
12:32:26.0 (327972391)|VARIABLE_SCOPE_BEGIN|[170]|result|Database.SaveResult|true|false
12:32:26.0 (327990129)|VARIABLE_ASSIGNMENT|[170]|result|{"success":true,"id":"02s4XXX"}|0x3714391c
12:32:26.0 (327994561)|STATEMENT_EXECUTE|[170]
12:32:26.0 (328026370)|STATEMENT_EXECUTE|[171]
12:32:26.0 (328037260)|SYSTEM_METHOD_ENTRY|[170]|system.ListIterator.hasNext()
Does anyone have an idea of what is happening ?
Thanks
Hi
Valentin M
queryMandrill(mandrillInfoUrl, m);
convertMandrillStatus((String) data.get('state'));
just tell me both methods returns types so send full coad then I will do some thing ok
Thanks
Thank you for your help !
Valentin M
you will inserts not updates beacuase if you are trying to update you need record id is must
in your code did not have record id;so its not possible
Thanks
This is not the issue, the emailMessages list is loaded using a SOQL query, they all exists in the db and have ids.
Thanks for your help.