1
//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;
        acc.Ammount__c=acc.Ammount__c-(acc.Ammount__c*discount);
    }
    }

}

and my test class is

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

        Account o1 = new Account();
        o1.Name='bhagyashri';

        o1.Ammount__c=1000.00; 

        insert o1;

        Account pAccount=[select Id,Name,Ammount__c from Account where Name='bhagyashri'];
        System.assert(pAccount.Ammount__c==900.00);   

  }
}

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

0

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.

1

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) {
    System.debug(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.