//this is my before insert trigger

public with sharing class Account_Amount 
    public Account_Amount(){} 

    public void calAmmount(List<Account> accList){
    AccountDiscount__c mc = AccountDiscount__c.getValues('AllUser');
    for(Account acc: accList)
        Double discount=mc.AcctDiscount__c/100;


and my test class is

public with sharing class Test_Acc_Amount
     static testMethod void test1(){

        Account o1 = new Account();


        insert o1;

        Account pAccount=[select Id,Name,Ammount__c from Account where Name='bhagyashri'];


I'm getting error failure message: system.dmlexception insert failed and getting code coverage 87 %


Looks like your trigger code is retrieving a custom setting value.

Which API version is your test class written in? Because current versions default to seealldata=false which means that there won't be any data in the custom settings during the test execution.


it's a good idea to always wrap your DML calls in try/catch blocks like this:

try {
    insert / update / delete / undelete statement
} catch (DMLException dmle) {

Doing so will let you know WHY your DML is failing.

  • I totally recommend this. – MnZ Jun 6 '14 at 15:25

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.