Activity Forums Salesforce® Discussions How to capture errors after using Database DML methods in Salesforce?

  • Laveena

    Member
    August 28, 2019 at 4:45 am

    Hi Prachi,

    List<Contact> lstContact = new List<Contact>();
    Contact con = new Contact (lastName = ‘Zaa’, SQL_Server_Id__c=’3′,firstName=’Jitendra’);
    lstContact.add(con);
    //.. Other Contact records added in List
    Database.UpsertResult[] results = Database.upsert( lstSGAccOppInsert, Contact.SQL_Server_Id__c.getDescribe().getSObjectField() ,false ) ;

    for(Integer i=0;i<results.size();i++){
    if (!results.get(i).isSuccess()){
    Database.Error err = results.get(i).getErrors().get(0);
    System.debug(‘Error – ‘+err.getMessage() + ‘nStatus Code : ‘+err.getStatusCode()+’n Fields : ‘+err.getFields());
    }
    }

    Thanks

Log In to reply.

Popular Salesforce Blogs

Popular Salesforce Videos