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

TestClass Code coverage......................
HI plz help how to achive good coverage for below class
Standard contoller="ACCOUNT" Extension ="Create_Multiple"
public class Create_Multiple{
public Opportunity {get; set;}
public Account acc{get; set;}
public string mal{set;get;}
public String marketsString {get; set;}
public List<String> selectedMarketsList {get; set;}
public Create_Multiple(ApexPages.StandardController opp){
oppLocal= new Opportunity();
oppsToCreateList=new list<Opportunity>();
mal=ApexPages.CurrentPage().getParameters().get('id');
system.debug('AAAAAAAAAAAAAAAACCCCCCCCCCCCCOunt'+mal);
acc=[select id,name,CP_Hierarchy__c from account where id=:mal];
}
public PageReference generateAllClones(){
marketsString = oppLocal.Opportunity_Markets__c;
selectedMarketsList = new List<String>();
if (Utility.isNotNull(marketsString))
{
selectedMarketsList = marketsString.split(';');
}
//oppsToCreateList.add(oppLocal);
//## iterate over the selected markets and create an Opp for each one...
for (Integer i=0; i<selectedMarketsList.size(); i++)
{
String themkt = selectedMarketsList.get(i);
boolean alreadyAdded = false;
//## see if the Market is already in the oppsToCreateList
for (Opportunity tmpopp : oppsToCreateList)
{
if (themkt == tmpopp.Opportunity_Market__c)
{
alreadyAdded = true;
}
}
if (themkt == oppLocal.Opportunity_Market__c || alreadyAdded)
{
//## don't re-add the original opp to the list, and don't
//## add the same record to the list multiple times.
}
else
{
Opportunity newopp = oppLocal.clone(false);
String thenom = acc.Name;
//thenom = thenom + ' - ' + themkt;
newopp.Opportunity_Market__c = themkt;
newopp.accountid=mal;
newopp.stagename='1 - Prospect Evaluation';
newopp.closedate=date.today();
newopp.RecordTypeId='012Z000000096eo';
if (thenom.length() > 80)
{
thenom = thenom.substring(0,80);
}
newopp.Name = acc.Name;
oppsToCreateList.add(newopp);
}
}
return null;
}
public PageReference doOppClone()
{
System.Debug(' oppsToCreate:'+oppsToCreateList);
if (oppsToCreateList != null && oppsToCreateList.size() > 0)
{
try
{
insert oppsToCreateList;
}
catch (Exception e)
{
ApexPages.addMessages(e);
return null;
}
}
return new PageReference('/'+acc.Id);
}
public List<Opportunity> oppsToCreateList {get;set;}
}
Standard contoller="ACCOUNT" Extension ="Create_Multiple"
public class Create_Multiple{
public Opportunity {get; set;}
public Account acc{get; set;}
public string mal{set;get;}
public String marketsString {get; set;}
public List<String> selectedMarketsList {get; set;}
public Create_Multiple(ApexPages.StandardController opp){
oppLocal= new Opportunity();
oppsToCreateList=new list<Opportunity>();
mal=ApexPages.CurrentPage().getParameters().get('id');
system.debug('AAAAAAAAAAAAAAAACCCCCCCCCCCCCOunt'+mal);
acc=[select id,name,CP_Hierarchy__c from account where id=:mal];
}
public PageReference generateAllClones(){
marketsString = oppLocal.Opportunity_Markets__c;
selectedMarketsList = new List<String>();
if (Utility.isNotNull(marketsString))
{
selectedMarketsList = marketsString.split(';');
}
//oppsToCreateList.add(oppLocal);
//## iterate over the selected markets and create an Opp for each one...
for (Integer i=0; i<selectedMarketsList.size(); i++)
{
String themkt = selectedMarketsList.get(i);
boolean alreadyAdded = false;
//## see if the Market is already in the oppsToCreateList
for (Opportunity tmpopp : oppsToCreateList)
{
if (themkt == tmpopp.Opportunity_Market__c)
{
alreadyAdded = true;
}
}
if (themkt == oppLocal.Opportunity_Market__c || alreadyAdded)
{
//## don't re-add the original opp to the list, and don't
//## add the same record to the list multiple times.
}
else
{
Opportunity newopp = oppLocal.clone(false);
String thenom = acc.Name;
//thenom = thenom + ' - ' + themkt;
newopp.Opportunity_Market__c = themkt;
newopp.accountid=mal;
newopp.stagename='1 - Prospect Evaluation';
newopp.closedate=date.today();
newopp.RecordTypeId='012Z000000096eo';
if (thenom.length() > 80)
{
thenom = thenom.substring(0,80);
}
newopp.Name = acc.Name;
oppsToCreateList.add(newopp);
}
}
return null;
}
public PageReference doOppClone()
{
System.Debug(' oppsToCreate:'+oppsToCreateList);
if (oppsToCreateList != null && oppsToCreateList.size() > 0)
{
try
{
insert oppsToCreateList;
}
catch (Exception e)
{
ApexPages.addMessages(e);
return null;
}
}
return new PageReference('/'+acc.Id);
}
public List<Opportunity> oppsToCreateList {get;set;}
}
but anyways how much is it now?
Refer the below link and change according to your code.
https://developer.salesforce.com/forums?id=906F00000008y7QIAQ
my code coverage upto 40% plz help
public class Create_Multiple_opportunities {
public Opportunity oppLocal {get; set;}
public Account acc{get; set;}
public string mal{set;get;}
public String marketsString {get; set;}
public List<String> selectedMarketsList {get; set;}
public Create_Multiple_opportunities(ApexPages.StandardController opp){
oppLocal= new Opportunity();
oppsToCreateList=new list<Opportunity>();
mal=ApexPages.CurrentPage().getParameters().get('id');
system.debug('AAAAAAAAAAAAAAAACCCCCCCCCCCCCOunt'+mal);
acc=[select id,name,CP_Hierarchy_Level_Type__c from account where id=:mal];
}
public PageReference generateAllClones(){
marketsString = oppLocal.Opportunity_Market_Multi__c;
selectedMarketsList = new List<String>();
if (Utility.isNotNull(marketsString))
{
selectedMarketsList = marketsString.split(';');
}
//oppsToCreateList.add(oppLocal);
//## iterate over the selected markets and create an Opp for each one...
for (Integer i=0; i<selectedMarketsList.size(); i++)
{
String themkt = selectedMarketsList.get(i);
boolean alreadyAdded = false;
//## see if the Market is already in the oppsToCreateList
for (Opportunity tmpopp : oppsToCreateList)
{
if (themkt == tmpopp.Opportunity_Market__c)
{
alreadyAdded = true;
}
}
if (themkt == oppLocal.Opportunity_Market__c || alreadyAdded)
{
//## don't re-add the original opp to the list, and don't
//## add the same record to the list multiple times.
}
else
{
Opportunity newopp = oppLocal.clone(false);
String thenom = acc.Name;
//thenom = thenom + ' - ' + themkt;
newopp.Opportunity_Market__c = themkt;
newopp.accountid=mal;
newopp.stagename='1 - Prospect Evaluation';
newopp.closedate=date.today();
newopp.RecordTypeId='012Z000000096eo';
if (thenom.length() > 80)
{
thenom = thenom.substring(0,80);
}
newopp.Name = acc.Name;
oppsToCreateList.add(newopp);
}
}
return null;
}
public PageReference doOppClone()
{
System.Debug(' oppsToCreate:'+oppsToCreateList);
if (oppsToCreateList != null && oppsToCreateList.size() > 0)
{
try
{
insert oppsToCreateList;
}
catch (Exception e)
{
ApexPages.addMessages(e);
return null;
}
}
return new PageReference('/'+acc.Id);
}
public List<Opportunity> oppsToCreateList {get;set;}
}