You need to sign in to do that
Don't have an account?
Please help me to increase code coverage
@AuraEnabled
public static void updateApplicationSeqNumber(String OpptyIdSet){
Opportunity givenOpportunity = [Select Id, Application_Sequence_Number__c, Application_number__c from Opportunity where Id =: OpptyIdSet WITH SECURITY_ENFORCED];
System_Configuration__c seqNumber = System_Configuration__c.getValues('System Configuration');
//for(Opportunity op : opptyList){
if(seqNumber.Application_Date__c == System.today()){
if(seqNumber.Application_Sequence_No__c==null){
seqNumber.Application_Sequence_No__c=1;
}else{
seqNumber.Application_Sequence_No__c=seqNumber.Application_Sequence_No__c+1;
}
givenOpportunity.Application_Sequence__c = seqNumber.Application_Sequence_No__c;
}
else{
givenOpportunity.Application_Sequence__c=00001;
seqNumber.Application_Sequence_No__c=00001;
seqNumber.Application_Date__c =System.today();
}
String text=String.valueOf(givenOpportunity.Application_Sequence__c);
text=text.substringBefore('.');
text=text.leftPad(5, '0');
String todayYear = String.valueOf(System.today().Year()).right(2);
String todayMonth = String.valueOf(system.today().Month()).length() == 1 ? '0' + String.valueOf(system.today().Month()) : String.valueOf(system.today().Month());
String todayDay = String.valueOf(system.today().day()).length() == 1 ? '0' + String.valueOf(system.today().day()) : String.valueOf(system.today().day());
String datePrefix = todayDay + '' + todayMonth + '' + todayYear;
String finalLeadNumber = '';
if(Test.isRunningTest() == false){
String applicationNameString = datePrefix + text;
Long appvalue = Long.valueOf(applicationNameString);
if (String.valueOf(appvalue).length() == 10) {
//adding '0' to Lead No pattern if date ranges in 01-09
finalLeadNumber = 'A' + '' + '0' + '' + String.valueOf(appvalue);
} else {
finalLeadNumber = 'A' + '' + String.valueOf(appvalue);
}
givenOpportunity.Application_number__c = finalLeadNumber;
}
// }
update seqNumber;
update givenOpportunity;
}
@isTest
public static void updateApplicationSeqNumberTest(){
Opportunity opun1 = new Opportunity();
opun1.StageName = 'Qualification';
opun1.CloseDate = Date.newInstance(2021, 1, 11);
opun1.Name = 'testone';
insert opun1;
Test.startTest();
UniqueLeadNumberHandler.updateApplicationSeqNumber(opun1.Id);
Test.stopTest();
}
try with below code.
If this helps, Please mark it as best answer.
Thanks!!