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

Apex test class coverage 57%
Hello,
I have apex class and apex test_Class. my coverage is on 57%. Please can someone help me.
My Apex Class:
public class show_opp {
@AuraEnabled
public static void updateEntityInfos(string entityWrapperList, String year,Decimal Amount, Decimal GrandC,Decimal NewBus, String Zone,Decimal AutresC) {
Decimal Amounts = Amount;
string zonee= Zone;
ID currentiduser;
List <user> currentiduserlist=[Select id from user where id =: Label.userassign limit 1];
if (currentiduserlist.size() > 0)
{
currentiduser = currentiduserlist[0].id;
}
List<String> zones = new list<String> { 'A1' , 'A2' , 'A3', 'A4'};
If (entityWrapperList != null){
id recordtypeid;
List <recordtype> RecordtypeOpp= [Select id from recordtype where id =: Label.ObjectifGlobalOpp limit 1];
if (RecordtypeOpp.size() > 0)
{
recordtypeid = RecordtypeOpp[0].id;
}
List<EntityWrapperClass> ObjList = new List<EntityWrapperClass>();
ObjList =(List<EntityWrapperClass>)System.JSON.deserialize(entityWrapperList,List<EntityWrapperClass>.class);
List<Opportunity> opportunityList = new List<Opportunity>();
List<Opportunity> opportunityListup = new List<Opportunity>();
for(EntityWrapperClass obj:ObjList ){
opportunity o=new opportunity();
string zonename= obj.name;
if (zones.contains(zonename))
{
o.Zone__C=obj.name;
o.ObjZoneEuro__c = obj.turnover;
o.Objectif_Global_Zone__c=obj.globalObjective;
}
else
{
o.Agence__c=obj.name;
o.Zone__C=zonee;
o.Objectif_Global_Agence__c=obj.globalObjective;
}
o.Global_New_Business__c=obj.newBusiness;
o.Global_Major_Account__c=obj.b2b;
o.Global_Other__c=obj.others;
o.Objectif_CA__c=Amounts;
o.Id= obj.opportunityId;
o.ObjectifYear__c = year;
o.OwnerId = currentiduser;
o.CloseDate = Date.newInstance(Integer.valueOf(year), 12, 31);
o.StageName = 'Qualification';
opportunityList.add(o);
}
for (Opportunity o:opportunityList)
{
}
upsert opportunityList;
}
{
id recordtypeidg;
List <recordtype> RecordtypeOppg= [Select id from recordtype where id =: Label.ObjectifGlobalOpp limit 1];
if (RecordtypeOppg.size() > 0)
{
recordtypeidg = RecordtypeOppg[0].id;
}
List<Opportunity> OpportunityGlobal = [Select id, Objectif_CA__c, Global_New_Business__c,Global_Major_Account__c, Global_Other__c from Opportunity where recordtypeid =: recordtypeidg and ObjectifYear__c =: year ORDER BY Createddate DESC LIMIT 1];
system.debug('OpportunityGlobal ' +OpportunityGlobal );
if (OpportunityGlobal.size()>0){
Decimal NewBusiness = NewBus;
Decimal GrandCs = GrandC;
Decimal AutresCs = AutresC;
OpportunityGlobal[0].CloseDate = Date.newInstance(Integer.valueOf(year), 12, 31);
OpportunityGlobal[0].Objectif_CA__c = Amounts;
OpportunityGlobal[0].Global_New_Business__c = NewBusiness;
OpportunityGlobal[0].Global_Major_Account__c = GrandCs;
OpportunityGlobal[0].Global_Other__c = AutresCs;
OpportunityGlobal[0].ObjectifYear__c = year;
OpportunityGlobal[0].OwnerId = currentiduser;
OpportunityGlobal[0].recordtypeid = recordtypeidg;
Database.upsert(OpportunityGlobal);
}
}
}
}
My Apex Test_Class:
@IsTest
public class show_opp_Test {
@isTest
// run the the class test
static void showoppTest() {
// Test data setup
String result;
Test.startTest();
LNCO5_ShowObjectifAnnuelSopexa.updateEntityInfos ('[{"b2b":10,"globalObjective":21,"name":"A1","newBusiness":"6","opportunityId":"0065E00000CDKWwQAP","others":80,"turnover":14910000},{"b2b":20,"globalObjective":22,"name":"A2","newBusiness":10,"opportunityId":"0065E00000CDKWvQAP","others":"8","turnover":15620000},{"b2b":3,"globalObjective":12,"name":"A3","newBusiness":4,"opportunityId":"0065E00000CDKWuQAP","others":80,"turnover":8520000},{"b2b":3,"globalObjective":14,"name":"A4","newBusiness":60,"opportunityId":"0065E00000CDKWtQAP","others":"10","turnover":9940000}]','2019', 7000, 20 ,19, 'A1', 35);
Test.stopTest();
// System.assertEquals('SUCCESS' , result);
}
}
I have apex class and apex test_Class. my coverage is on 57%. Please can someone help me.
My Apex Class:
public class show_opp {
@AuraEnabled
public static void updateEntityInfos(string entityWrapperList, String year,Decimal Amount, Decimal GrandC,Decimal NewBus, String Zone,Decimal AutresC) {
Decimal Amounts = Amount;
string zonee= Zone;
ID currentiduser;
List <user> currentiduserlist=[Select id from user where id =: Label.userassign limit 1];
if (currentiduserlist.size() > 0)
{
currentiduser = currentiduserlist[0].id;
}
List<String> zones = new list<String> { 'A1' , 'A2' , 'A3', 'A4'};
If (entityWrapperList != null){
id recordtypeid;
List <recordtype> RecordtypeOpp= [Select id from recordtype where id =: Label.ObjectifGlobalOpp limit 1];
if (RecordtypeOpp.size() > 0)
{
recordtypeid = RecordtypeOpp[0].id;
}
List<EntityWrapperClass> ObjList = new List<EntityWrapperClass>();
ObjList =(List<EntityWrapperClass>)System.JSON.deserialize(entityWrapperList,List<EntityWrapperClass>.class);
List<Opportunity> opportunityList = new List<Opportunity>();
List<Opportunity> opportunityListup = new List<Opportunity>();
for(EntityWrapperClass obj:ObjList ){
opportunity o=new opportunity();
string zonename= obj.name;
if (zones.contains(zonename))
{
o.Zone__C=obj.name;
o.ObjZoneEuro__c = obj.turnover;
o.Objectif_Global_Zone__c=obj.globalObjective;
}
else
{
o.Agence__c=obj.name;
o.Zone__C=zonee;
o.Objectif_Global_Agence__c=obj.globalObjective;
}
o.Global_New_Business__c=obj.newBusiness;
o.Global_Major_Account__c=obj.b2b;
o.Global_Other__c=obj.others;
o.Objectif_CA__c=Amounts;
o.Id= obj.opportunityId;
o.ObjectifYear__c = year;
o.OwnerId = currentiduser;
o.CloseDate = Date.newInstance(Integer.valueOf(year), 12, 31);
o.StageName = 'Qualification';
opportunityList.add(o);
}
for (Opportunity o:opportunityList)
{
}
upsert opportunityList;
}
{
id recordtypeidg;
List <recordtype> RecordtypeOppg= [Select id from recordtype where id =: Label.ObjectifGlobalOpp limit 1];
if (RecordtypeOppg.size() > 0)
{
recordtypeidg = RecordtypeOppg[0].id;
}
List<Opportunity> OpportunityGlobal = [Select id, Objectif_CA__c, Global_New_Business__c,Global_Major_Account__c, Global_Other__c from Opportunity where recordtypeid =: recordtypeidg and ObjectifYear__c =: year ORDER BY Createddate DESC LIMIT 1];
system.debug('OpportunityGlobal ' +OpportunityGlobal );
if (OpportunityGlobal.size()>0){
Decimal NewBusiness = NewBus;
Decimal GrandCs = GrandC;
Decimal AutresCs = AutresC;
OpportunityGlobal[0].CloseDate = Date.newInstance(Integer.valueOf(year), 12, 31);
OpportunityGlobal[0].Objectif_CA__c = Amounts;
OpportunityGlobal[0].Global_New_Business__c = NewBusiness;
OpportunityGlobal[0].Global_Major_Account__c = GrandCs;
OpportunityGlobal[0].Global_Other__c = AutresCs;
OpportunityGlobal[0].ObjectifYear__c = year;
OpportunityGlobal[0].OwnerId = currentiduser;
OpportunityGlobal[0].recordtypeid = recordtypeidg;
Database.upsert(OpportunityGlobal);
}
}
}
}
My Apex Test_Class:
@IsTest
public class show_opp_Test {
@isTest
// run the the class test
static void showoppTest() {
// Test data setup
String result;
Test.startTest();
LNCO5_ShowObjectifAnnuelSopexa.updateEntityInfos ('[{"b2b":10,"globalObjective":21,"name":"A1","newBusiness":"6","opportunityId":"0065E00000CDKWwQAP","others":80,"turnover":14910000},{"b2b":20,"globalObjective":22,"name":"A2","newBusiness":10,"opportunityId":"0065E00000CDKWvQAP","others":"8","turnover":15620000},{"b2b":3,"globalObjective":12,"name":"A3","newBusiness":4,"opportunityId":"0065E00000CDKWuQAP","others":80,"turnover":8520000},{"b2b":3,"globalObjective":14,"name":"A4","newBusiness":60,"opportunityId":"0065E00000CDKWtQAP","others":"10","turnover":9940000}]','2019', 7000, 20 ,19, 'A1', 35);
Test.stopTest();
// System.assertEquals('SUCCESS' , result);
}
}
Try this test class:
Let me know if it helps
Thanks