Advertisement
Guest User

Untitled

a guest
May 30th, 2015
301
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.09 KB | None | 0 0
  1. // Create a list of contacts
  2.  
  3. List<Contact> conList = new List<Contact> {
  4. new Contact(FirstName='Joe',LastName='Smith',Department='Finance'),
  5. new Contact(FirstName='Kathy',LastName='Smith',Department='Technology'),
  6. new Contact(FirstName='Caroline',LastName='Roth',Department='Finance'),
  7.  
  8. new Contact()};
  9.  
  10.  
  11. // Bulk insert all contacts with one DML call
  12. Database.SaveResult[] srList = Database.insert(conList, false);
  13.  
  14.  
  15.  
  16. // Iterate through each returned result
  17. for (Database.SaveResult sr : srList) {
  18.  
  19. if (sr.isSuccess()) {
  20.  
  21. // Operation was successful, so get the ID of the record that was processed
  22.  
  23. System.debug('Successfully inserted contact. Contact ID: ' + sr.getId());
  24.  
  25. } else {
  26.  
  27. // Operation failed, so get all errors
  28.  
  29. for(Database.Error err : sr.getErrors()) {
  30.  
  31. System.debug('The following error has occurred.');
  32. System.debug(err.getStatusCode() + ': ' + err.getMessage());
  33. System.debug('Contact fields that affected this error: ' + err.getFields());
  34.  
  35. }
  36.  
  37. }
  38.  
  39. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement