Skip to main content
vetriselvan manoharan (Wilco Source) 님이 #Apex에 질문했습니다
Hi,

While updating data via data laoder and it will trigger the operation. If the 3rd record enters in custom validation condition, the update fails and the all the records displaying same validation message. Please clear it.

Thanks,

Vetri
답변 34개
  1. 2015년 2월 20일 오전 6:31
    Sample code:-

    Map<String, List<Object>> errorRecords = new Map<String, List<Object>>();

    if(condition1 met) {

            acc.addError(' MyError1');   //Don't throw error here (i.e. don't use this line here)      

            if(errorRecords.contains('MyError1')) {

                errorRecords.get('MyError1').add(acc);

            } else {

                errorRecords.put('MyError1', new List<Object>(acc));

            }

            

    } else if(condition2 met) {

            acc.addError(' MyError2');   //Don't throw error here (i.e. don't use this line here)       

            if(errorRecords.contains('MyError2')) {

                errorRecords.get('MyError2').add(acc);

            } else {

                errorRecords.put('MyError2', new List<Object>(acc));

            }

    }

    .

    .

    .else if(condition10 met) {

            acc.addError(' MyError10');   //Don't throw error here (i.e. don't use this line here)       

            if(errorRecords.contains('MyError10')) {

                errorRecords.get('MyError10').add(acc);

            } else {

                errorRecords.put('MyError10', new List<Object>(acc));

            }

    } else {

    }

    In the end after everything is done

    for(String str : errorRecords.keySet) {

        for(Object o : errorRecords.get(str)) {

            o.addError(str);

        }

    }