You need to sign in to do that
Don't have an account?

System.DmlException: Insert failed. First exception in test class
controller
public class AddmultipleAccountsController {
Account account = new Account();
public list<Account> listAccount{ get; set; }
public AddmultipleAccountsController()
{
listAccount=new list<Account>();
listAccount.add(account);
}
Public void addAccount()
{
Account acc = new Account();
listAccount.add(acc);
}
public PageReference saveAccount() {
for(Integer i=0; i<listAccount.size(); i++)
{
insert listAccount;
}
return Page.addmore;
}
}
test class
@isTest
public class addmul_test
{
static testmethod void addtest()
{
AddmultipleAccountsController ar=new AddmultipleAccountsController();
pagereference pf=Page.addmore;
ar.addAccount();
ar.saveAccount();
}
}
public class AddmultipleAccountsController {
Account account = new Account();
public list<Account> listAccount{ get; set; }
public AddmultipleAccountsController()
{
listAccount=new list<Account>();
listAccount.add(account);
}
Public void addAccount()
{
Account acc = new Account();
listAccount.add(acc);
}
public PageReference saveAccount() {
for(Integer i=0; i<listAccount.size(); i++)
{
insert listAccount;
}
return Page.addmore;
}
}
test class
@isTest
public class addmul_test
{
static testmethod void addtest()
{
AddmultipleAccountsController ar=new AddmultipleAccountsController();
pagereference pf=Page.addmore;
ar.addAccount();
ar.saveAccount();
}
}
if(!Test.isRunningTest()) {
insert listAccount;
}
Your test class won't be failed and you will get most of the code coverage. In case of failurese we cannot deploy.
------------
Thanks,
Srinivas
- Please mark as solution if your problem is resolved.
All Answers
Test Class -
Please as mentioned above.
------------
Thanks,
Srinivas
- Please mark as solution if your problem is resolved.
i tried this
public class AddmultipleAccountsController {
Account account = new Account();
public list<Account> listAccount{ get; set; }
public AddmultipleAccountsController()
{
listAccount=new list<Account>();
listAccount.add(account);
}
Public void addAccount()
{
Account acc = new Account();
listAccount.add(acc);
}
public PageReference saveAccount() {
insert listAccount;
//return null;
return Page.addmore;
}
}
****************************************
@isTest
public class addmul_test
{
public static testmethod void addtest()
{
AddmultipleAccountsController ar=new AddmultipleAccountsController();
pagereference pf=Page.addmore;
Account a=new Account();
a.Name='dev';
ar.listAccount.add(a);
ar.addAccount();
ar.saveAccount();
}
}
why this is not working..
giving a faliure of required field missing
thnks
------------
Thanks,
Srinivas
- Please mark as solution if your problem is resolved.
and i have a query that..if the code coverage is more than 75% and there is failure occur after clicking run test..then can we deploy the class??
if(!Test.isRunningTest()) {
insert listAccount;
}
Your test class won't be failed and you will get most of the code coverage. In case of failurese we cannot deploy.
------------
Thanks,
Srinivas
- Please mark as solution if your problem is resolved.
its working