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
Valentin MValentin 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).
 
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
sandeep reddy 37sandeep reddy 37

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 
 
Valentin MValentin M
private static Map<String, Object> queryMandrill(String url, EmailMessage emailMessage);
private static String convertMandrillStatus(String mandrillStatus);
The first method does the callout, parses some JSON and replies with a key-value map representation of this JSON. The second is just a string conversion to match the picker values I have in salesforce. Both of these methods work well.

Thank you for your help !
 
sandeep reddy 37sandeep reddy 37
Hi
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
 
Valentin MValentin M
Hi Sandeep, 

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.