You need to sign in to do that
Don't have an account?
Guru@SfCloud
Urgency for Test Code Coverage
Hi all, right now i am facing the code coverage issue ,my current code coverage is 41% ,can any one suggest me how to make it as 100% thanks in advance
my code is
Bold line are not get covered
Public class CreatingAssetsForOpportunities_class{
Public static List<Asset> AssetLst = new List<Asset>();
Public static Asset Assets = new Asset();
public static void insertAssets(List<Opportunity> OppLst){
System.debug('Method called from trigger');
for(Opportunity O : OppLst){
if(OppLst.size()>0){
System.debug('O.Sync_to_Sage__c : '+O.Sync_to_Sage__c);
if(O.Sync_to_Sage__c == 'Sent to Sage'){
System.debug('O.OpportunityLineItems.size : '+O.OpportunityLineItems.size());
if(O.OpportunityLineItems.size()>0){
for(OpportunityLineItem OLI : O.OpportunityLineItems){
for(integer i = 0; i < OLI.Quantity; i++){
//Asset Assets = new Asset();
Assets = insertingMethod(OLI);
system.debug('Assets : '+insertingMethod(OLI));
AssetLst.add(Assets);
//insert AssetLst;
}
}
insert AssetLst;
}
}
}
}
}
Public static Asset insertingMethod(OpportunityLineItem OLItoUseForAssetInsert){
Asset A = new Asset();
A.name = OLItoUseForAssetInsert.name;
//A.ProductCode = OLItoUseForAssetInsert.ProductCode; //Error : Invalid field ProductCode for SObject Asset
//A.Description__c = OLItoUseForAssetInsert.Description; //Error: Field is not writeable: Asset.Description__c
//A.Supplier__C = OLItoUseForAssetInsert.;
//no dimentions field
//no equipment Cost
A.Enquiry__c = OLItoUseForAssetInsert.Opportunity.Id;
//AssetLst.add(A);
return A;
}
}
my code is
Bold line are not get covered
Public class CreatingAssetsForOpportunities_class{
Public static List<Asset> AssetLst = new List<Asset>();
Public static Asset Assets = new Asset();
public static void insertAssets(List<Opportunity> OppLst){
System.debug('Method called from trigger');
for(Opportunity O : OppLst){
if(OppLst.size()>0){
System.debug('O.Sync_to_Sage__c : '+O.Sync_to_Sage__c);
if(O.Sync_to_Sage__c == 'Sent to Sage'){
System.debug('O.OpportunityLineItems.size : '+O.OpportunityLineItems.size());
if(O.OpportunityLineItems.size()>0){
for(OpportunityLineItem OLI : O.OpportunityLineItems){
for(integer i = 0; i < OLI.Quantity; i++){
//Asset Assets = new Asset();
Assets = insertingMethod(OLI);
system.debug('Assets : '+insertingMethod(OLI));
AssetLst.add(Assets);
//insert AssetLst;
}
}
insert AssetLst;
}
}
}
}
}
Public static Asset insertingMethod(OpportunityLineItem OLItoUseForAssetInsert){
Asset A = new Asset();
A.name = OLItoUseForAssetInsert.name;
//A.ProductCode = OLItoUseForAssetInsert.ProductCode; //Error : Invalid field ProductCode for SObject Asset
//A.Description__c = OLItoUseForAssetInsert.Description; //Error: Field is not writeable: Asset.Description__c
//A.Supplier__C = OLItoUseForAssetInsert.;
//no dimentions field
//no equipment Cost
A.Enquiry__c = OLItoUseForAssetInsert.Opportunity.Id;
//AssetLst.add(A);
return A;
}
}
Please refer to links below that will help you to increase the code coverage:
1.http://stackoverflow.com/questions/11759893/salesforce-trigger-code-coverage-stuck-at-35-no-matter-what-i-do
2.http://salesforce.stackexchange.com/questions/29204/how-can-i-increase-my-code-coverage-in-test-class
3.http://salesforce.stackexchange.com/questions/25892/the-most-sneaky-way-to-increase-your-code-coverage
4.http://stackoverflow.com/questions/19173874/need-help-in-improving-test-coverage-to-75-apex-class
5.https://help.salesforce.com/HTViewHelpDoc?id=code_dev_console_tests_coverage.htm&language=en_US
6.https://developer.salesforce.com/forums/ForumsMain?id=906F00000008ofvIAA
7.http://forcebydesign.com/technology/apex-code-coverage-75-or-bust/
I hope this helps.