You need to sign in to do that
Don't have an account?
Eric Blaxton 11
How to get Database.UpsertResult to show work
Hi and thanks in advance.
I want to see the records that were created or updated via Database.UpsertResult. The records are being updated and/or created, but I am not getting ANY results from the for loop.
Any ideas?
Eric
I want to see the records that were created or updated via Database.UpsertResult. The records are being updated and/or created, but I am not getting ANY results from the for loop.
Any ideas?
Schema.SObjectField f = Case.Ticket_Number__c; Database.UpsertResult [] cr = Database.upsert(toBeUpsertCases, f, false); // I want to see what was updated / created for(Integer index = 0; index < cr.size(); index++ ) { if(cr[index].isSuccess()) { if(cr[index].isCreated()) { System.debug(toBeUpsertCases[index].Ticket_Number__c + ' was created'); } else { System.debug(toBeUpsertCases[index].Ticket_Number__c + ' was updated'); } } }// end for loop
Eric
Hello Eric!
I altered your code a little.
Also, please note that if the Ticket_Number__c isn't set on creation, it would print "null was created".
All Answers
Database.upsertResult contains the result of an upsert DML operation returned by the Database. upsert method. If you want to check the status of Database.Upsert transaction, that information will be available here. Also, the number of errors, sobject id where you performed the operation and all these details will be logged in this table.
Please read the below article.
https://developer.salesforce.com/docs/atlas.en-us.apexcode.meta/apexcode/apex_methods_system_database_upsertresult.htm#apex_Database_UpsertResult_getErrors
and for example, you can prefer the below one.
https://developer.salesforce.com/docs/atlas.en-us.apexcode.meta/apexcode/langCon_apex_dml_examples_upsert.htm
Let me know if it helps you and close your query by marking it as solved so that it can help others in the future.
Thanks!
Hello Eric!
I altered your code a little.
Also, please note that if the Ticket_Number__c isn't set on creation, it would print "null was created".
Appreciate your help on this.
Eric