Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Account z = new Account(Name=null);
- List<Account> contas = new List<Account>{new Account(Name='VolksWagen'),
- new Account(Name='Fiat'),
- z,
- new Account(Name='Jeep'),
- new Account(Name=null)};
- try{
- Database.SaveResult[] resultado = Database.insert(contas, false);
- List<Database.SaveResult> listaDBSR = new List<Database.SaveResult>();
- for(Database.SaveResult dsr:resultado){
- listaDBSR.add(dsr);
- }
- List<Database.SaveResult> success = new List<Database.SaveResult>();
- List<DataBase.Error> errors = new List <DataBase.Error>();
- Integer errorsIndexCount = 0;
- Map<Integer,List<DataBase.Error>> mapaErros = new Map<Integer,List<DataBase.Error>>();
- for(Database.SaveResult datasr:listaDBSR){
- if(datasr.isSuccess()){
- success.add(datasr);
- }else{
- errors = datasr.getErrors();
- mapaErros.put(errorsIndexCount, errors);
- }
- errorsIndexCount++;
- }
- System.debug('Registros com sucesso: ');
- for(Database.SaveResult s:success){
- System.debug(s.Id);
- }
- System.debug('Registros com erros: '+mapaErros.size()+' registros');
- for(Integer i:mapaErros.keySet()){
- System.debug('Registro nº '+i);
- for(Database.Error de:mapaErros.get(i)){
- System.debug(de.getMessage());
- System.debug(de.getStatusCode());
- System.debug(de.getFields());
- }
- }
- }catch(DMLException d){
- System.debug(d.getMessage());
- }
Advertisement
Add Comment
Please, Sign In to add comment