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

how to create test class
else{
integer k = 0;
for(Opportunity_Splits__c s :oSplit){
if(k == 0){
s.Practice__c= pract;
s.Percent__c= 100;
oppspiltUpdatelist.add(s);
k++;
}else{
oppspiltdeletelist.add(s);
}
}
}
}else{
if(oSplit.size() == 1){
for(Opportunity_Splits__c s :oSplit){
if(oldCount == 0){
s.Practice__c= pract;
s.Percent__c= 50;
oppspiltUpdatelist.add(s);
oldCount++;
}else{
Opportunity_Splits__c op =new Opportunity_Splits__c();
op.Practice__c= pract;
op.Percent__c= 50;
op.Opportunity__c= opp.id;
oppspiltNewlist.add(op);
}
}
}else{
if(oldValue == 0){
oSplit[0].Practice__c= pract;
oSplit[0].Percent__c= 50;
oppspiltUpdatelist.add(oSplit[0]);
oldIds.add(oSplit[0].id);
oldValue++;
}else if(oldValue == 1){
oSplit[1].Practice__c= pract;
oSplit[1].Percent__c= 50;
oppspiltUpdatelist.add(oSplit[1]);
oldIds.add(oSplit[1].id);
oldValue++;
System.debug('test ++ oSplit '+oSplit.size() +' , oldValue '+oldValue+' , oldIds '+oldIds);
if(oSplit.size() >2){
for(Opportunity_Splits__c s :oSplit){
if(!oldIds.Contains(s.id))
oppspiltdeletelist.add(s);
}
}
}
}
}
}else{
Opportunity_Splits__c ONew=new Opportunity_Splits__c();
ONew.Practice__c= pract;
ONew.Percent__c= 100;
ONew.Opportunity__c= opp.id;
oppspiltNewlist.add(ONew);
}
}
}
}
}
}
if(!oppspiltdeletelist.isEmpty())
delete oppspiltdeletelist;
if(!oppspiltUpdatelist.isEmpty())
update oppspiltUpdatelist;
if(!oppspiltNewlist.isEmpty())
insert oppspiltNewlist;
}
integer k = 0;
for(Opportunity_Splits__c s :oSplit){
if(k == 0){
s.Practice__c= pract;
s.Percent__c= 100;
oppspiltUpdatelist.add(s);
k++;
}else{
oppspiltdeletelist.add(s);
}
}
}
}else{
if(oSplit.size() == 1){
for(Opportunity_Splits__c s :oSplit){
if(oldCount == 0){
s.Practice__c= pract;
s.Percent__c= 50;
oppspiltUpdatelist.add(s);
oldCount++;
}else{
Opportunity_Splits__c op =new Opportunity_Splits__c();
op.Practice__c= pract;
op.Percent__c= 50;
op.Opportunity__c= opp.id;
oppspiltNewlist.add(op);
}
}
}else{
if(oldValue == 0){
oSplit[0].Practice__c= pract;
oSplit[0].Percent__c= 50;
oppspiltUpdatelist.add(oSplit[0]);
oldIds.add(oSplit[0].id);
oldValue++;
}else if(oldValue == 1){
oSplit[1].Practice__c= pract;
oSplit[1].Percent__c= 50;
oppspiltUpdatelist.add(oSplit[1]);
oldIds.add(oSplit[1].id);
oldValue++;
System.debug('test ++ oSplit '+oSplit.size() +' , oldValue '+oldValue+' , oldIds '+oldIds);
if(oSplit.size() >2){
for(Opportunity_Splits__c s :oSplit){
if(!oldIds.Contains(s.id))
oppspiltdeletelist.add(s);
}
}
}
}
}
}else{
Opportunity_Splits__c ONew=new Opportunity_Splits__c();
ONew.Practice__c= pract;
ONew.Percent__c= 100;
ONew.Opportunity__c= opp.id;
oppspiltNewlist.add(ONew);
}
}
}
}
}
}
if(!oppspiltdeletelist.isEmpty())
delete oppspiltdeletelist;
if(!oppspiltUpdatelist.isEmpty())
update oppspiltUpdatelist;
if(!oppspiltNewlist.isEmpty())
insert oppspiltNewlist;
}
Do You got a chance to check the Test generator app from App Exchange please check the below link
- Please follow below Salesforce Best Practice Link on Test Classes:- https://developer.salesforce.com/docs/atlas.en-us.apexcode.meta/apexcode/apex_qs_test.htm
- https://developer.salesforce.com/docs/atlas.en-us.apexcode.meta/apexcode/apex_testing_example.htm (http:// https://developer.salesforce.com/docs/atlas.en-us.apexcode.meta/apexcode/apex_testing_example.htm )
- http://amitsalesforce.blogspot.com/2015/06/best-practice-for-test-classes-sample.html
I hope it will be helpful.Please mark it as best answer if the information is informative.
Best Regards
Rahul Kumar