function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
garfergarfer 

Because I can not cover 100% a class that was already covered

Hello,

I have a problem, I created a class in eclipse that runs correctly in production. When I want more code appends, I class covers only 23%. I add the code that's just an assignment of values ​​to a new field of the object.


The strange thing is that I leave the class as it was running in production, and covers me 100%, in theory should cover, as this same code is running currently in production.

In order opportunity to add some custom field
 
Someone can help me solve this problem ...


thanks

 
IspitaIspita

Hi,

Though the exact cause analysis can be done if one goes through the code.

Yes it may happen that:-

  • There is an error in your code ~ run all tests and check the logs to see if any error has been encountered.
  • Also it might so happenthat your new code has added for conditional code with if-else and due to some reason some of the else or if statememts are not getting covered. 
  • You might have implemented condition for which you havent generated code or not created data to give due coverage.
  • The condition might be such that some conditions cannot be logically covered in the organizatgion's scenario.

 

Hope this helps...

UVUV

A class having 100 % code coverage in Sandbox may have less code coverage in the production because of some dependencies.So, its not always same.However, if there is a big difference in the coverage of Sandbox and Production then you should debug the code in the production by running the runtest for the that class ans see what code is not getting covered.

If you want to extend your functionality then you must review the test class as well in sandbox to make sure you have sufficient code coverage and then deploy the apex class and test class again.

There may be plenty of reasons for the low code coverage and I dont want to guess.Would be great if you post your code here in case you are not able to identify the root cause of the issue by debugging your code or log a case with salesforce. 

garfergarfer
Here is the code that it is running in production, this code is covered at 100%.
The ineas with red, are those that want to add.

I'm working with eclipse and when I run test mark error starting at the
line 9

I am new developing code Apex and hope I can help.

Thank you

 

CODE

global class BatchLeadPhones implementsDatabase.Batchable<sObject>{

publicString query, query1;

globaldatabase.querylocator start(Database.BatchableContext BC){

query='Select Id, Name, Nombre_del_Cliente__c, Proceso__c,Fecha_de_Pago__c, Mes_de_validacion__c From Factura__c Where Proceso__c='No validado' ';

returnDatabase.getQueryLocator(query);

}

globalvoid execute(Database.BatchableContext BC, List<sObject> scope){

List<Factura__c> Leads = new List<Factura__c>();

 for(sObject s : scope){

           Factura__c l = (Factura__c)s;

               for(List<Opportunity> st : [SELECT Id, Numero_de_la_Factura__c, Status_de_Oportunidad__c,     

            Status_Factura__c FROMOpportunityWHERE Numero_de_la_Factura__c =: l.Name]){

                    for(Opportunityopor:st){

                                    if (opor.Numero_de_la_Factura__c == l.Name){

                                             opor.Status_Factura__c ='Pagada';

                                  l.Proceso__c 'Terminado';

                                  opor.Fecha_de_pago__c=l.Fecha_de_Pago__c;

 

}

}

updatest;

}

Leads.Add(l);

}

update Leads;

 

}

globalvoidfinish(Database.BatchableContext BC){

}

// test method

static testMethod void test_BatchLeadPhones() {

 

Test.StartTest();

BatchLeadPhones Blp =

newBatchLeadPhones();

ID batchprocessid = Database.executeBatch(Blp);

Test.StopTest();

 

}

 

}

UVUV

Can you pls post the error????

garfergarfer

This is the error that throws me when I run the test run.

"The average test coverage of all classes and Apex triggers is 23%, requires a minimum test coverage of 75%"

From line 9 sends the problem:
My class (ApexClass) - -13 lines not tested, 24% covered

This code is currently being used in production, do not understand why send the code coverage issue.

 

thanks for you help