Stack Exchange Network

Stack Exchange network consists of 175 Q&A communities including Stack Overflow, the largest, most trusted online community for developers to learn, share their knowledge, and build their careers.

Visit Stack Exchange

Questions tagged [code-coverage]

Questions about specific lines of code that need coverage or platform bugs. 75% of your Apex code must be covered by test classes. This tag is not intended for use when code coverage is simply lacking, but for scenarios where because of a particular configuration or system issue code coverage is challenging.

0
votes
1answer
37 views

Please help write a Test Class for method for object UserRecordAccess (read only object i think)

Controller class public class Redirectcomp{ public String sCaseId {get;set;} public Redirectcomp(){ } public PageReference autorun() { sCaseId = ApexPages....
2
votes
3answers
587 views

Is my test coverage up to snuff? [closed]

I've got a theoretical, rather than a practical, question today. I just wrote the trigger and test class below. I'd love to get feedback on such questions as: 1. Do I test sufficient cases? (It gets ...
1
vote
2answers
42 views

Process Builder causing Apex Test class failures - How to handle?

Hoping someone can help with the following issue I am currently experiencing. I have created a new process via the process builder that sets the Contact owner to be the same as the Account Owner on ...
-2
votes
1answer
36 views

Can Somebody help me to optimize this test class. I want limit this test class to 100-150 lines

@isTest private class Verification_Callcenter_Test{ static Verification__c verobj = null; public static void CreateFirstCommonVerificationData() { verobj = new Verification__c(...
7
votes
1answer
138 views

Visual representation code coverage in VSCode

As per answer in this post, in order to get code coverage after running test classes from VSCode, we just need to add "-c" for the sfdx test command as below: sfdx force:apex:test:run -c -u myOrg -r ...
0
votes
1answer
29 views

Test Class for Trigger on Event [duplicate]

I am new to Salesforce and I am writing a test class for the trigger. Can anyone tell me how to write a test class for the trigger below? trigger QBRNewRec on Account (After insert, After Update) { ...
2
votes
1answer
37 views

No code coverage information was found for test run 7070U00000r8Ny3. Set “salesforcedx-vscode-core.retrieve-test-code-coverage”: true

In user setting.JSON I am using { "salesforcedx-vscode-apex.java.home":"C:\\Program Files\\Java\\jdk1.8.0_131", "salesforcedx-vscode-core.show-cli-success-msg": true, "salesforcedx-...
1
vote
1answer
34 views

DmlException: Merge failed. First exception on row 0 with id first error: DELETE_FAILED

Error: System.DmlException: Merge failed. First exception on row 0 with id first error: DELETE_FAILED,TargetX_SRMb.ContactTrigger: execution of AfterDelete caused by: System.NullPointerException: ...
2
votes
1answer
29 views

Upload beta package - how to bypass or speed up tests execution

We have our huge managed package (1st generation, i.e. classic one) and every time when we upload new beta version (even with just a few fixes) it takes up to 3 hours for the whole process to complete ...
2
votes
2answers
91 views

Unit test when a method calls another one

I have the current scenario and it's not clear which is the best way to test it. public class FirstClass { public Integer firstMethod() { return SecondClass.secondClass_Handler(); } } ...
0
votes
0answers
24 views

Salesforce documentation, how to write a test class for below code [duplicate]

I am trying to make a simple test class to get the code coverage. This is the class of the documentation in Salesforce which must be tested. Has anyone a sample for me :) ? Best regards. Constantin ...
-1
votes
1answer
25 views

Unable to cover try catch for UserPackageLicense test class

I have below UserPackageLicense class and test class.I am unable to cover the test class try catch block Class:- public class AssignPackageLicense { public static boolean flag=true; static String ...
0
votes
2answers
29 views

How to get test coverage of org while running validation jobs?

In our CI process, we trigger a job for validation in Jenkins and have an ant target which runs the validation first with checkOnly as true and runs all the tests. build.xml : <target name="...
2
votes
1answer
41 views

Apex code coverage and static boolean recursion flags

I've written two Apex Triggers, one on the Opportunity object, and one on a custom object. These two triggers keep the two objects' checkboxes in sync; setting a value on one object's value sets the ...
0
votes
2answers
33 views

How to test this return value in catch exception

I'm new to test classes, can anyone give me a help on this? Here's the class: global class CallTimerController { @AuraEnabled global static Integer getMaxCallDuration(){ Id pId = ...
0
votes
1answer
41 views

Test class for a scheduled batch is not firing the batch

I have tried the class in a sandbox and works fine (i.e. it updates all of the accounts based on the attached event records). The test class refuses to fire the batch class and I get 0% coverage. ...
2
votes
1answer
51 views

Code Coverage during sfdx force:mdapi:deploy

I am trying to do a sfdx force:mdapi:deploy to my production org. I am just migrating one class file, however when I do that I keep getting code coverage failures on custom classes that are already in ...
1
vote
1answer
132 views

Deploy from Sandbox to Production Org SFDX

I created an SFDX project with manifest in VSCODE, authorized my sandbox org and retrieved source from manifest on the default package.xml. At this point I had the base setup with classes, triggers, ...
1
vote
2answers
72 views

Is it a good practice to use a static variable in a Test Class and use that in the actual class instead of Test.isRunningTest()?

I've read about using a static variable from a class in the test class but I'm wondering if this is legal enough to do. @isTest public class myTestClass{ public static Boolean mySwitch = false; ...
-2
votes
1answer
45 views

I am getting stuck here, I just need test apex /snippet /mock for this. Any input will be highly appreciated [closed]

I am just new to apex testing, I am getting responce from Trigger upon that i am moving further in my class. let me know id there is a way around to get better understanding to develop test cases. ...
0
votes
0answers
25 views

How to increase the code coverage for the following Test Class, currently it covering only 50% [duplicate]

Actual Class: global class ITSSFAutoRejectBatch implements Database.Batchable<SObject>, Database.Stateful, Schedulable { global String[] toAddresses = null; global integer batchSize = 100; ...
0
votes
2answers
59 views

Testing or writing a test class for random string generator class

How can we unit test a random string generator class of this given code. I do get 100% code coverage, but I feel like the test is not executed properly. Any solutions to this will be helpful. Random ...
0
votes
1answer
31 views

How do you write a test for a class that clones? [duplicate]

I have the following code that clones an asset and its' children... public class Cloner { public Asset root_asset { get; set; } public Asset cloned_root_asset {get; set; } public ...
0
votes
0answers
26 views

Test class - code coverage help [duplicate]

I need help on test class, this is my class: When creating a task of type (Phone Call or Last Face to Face) then update the account fields I have a trigger: trigger TaskTrigger on Task (after ...
0
votes
0answers
41 views

System.ListException: List index out of bounds: 0 in test class when we try to query ProcessInstanceWorkitem [duplicate]

I am getting List index out of bounds exception when I try to query ProcessInstanceWorkitem in test class. Below is the code snippet in the main class: ProcessInstanceWorkitem[] piw = [SELECT Id ...
-1
votes
1answer
20 views

Test Method for Custom Controller that references Lists in Loops

I have the following custom controller that is pulling some Lists and subsequently looping back through the Lists to do some sums on the values to display them on a Visualforce Page I have only got ...
-1
votes
1answer
37 views

Not able to cover the IsConverted Logic from test class

Class: public class classname { public static void MethodName(List<Lead> listNew){ Set<Id> OppIds = new Set<Id>(); for(Lead lead : listNew) { if ...
5
votes
3answers
235 views

How to cover method return statement in Apex Class?

I'm writing a test for a schedulable class and so far it's working fine but I can't get the return statement to be covered by the test class. I'm missing something here and can't see it. The final ...
1
vote
1answer
28 views

Test error condition in batch class with callouts

I have an Apex class with a callout (oregonDistricts.apxc) and I have two tests written that test both the success and error conditions. These tests are passing and the class has 100% code coverage. ...
0
votes
1answer
24 views

How do I get my test class to cover the extension controller?

I am getting only 1% code coverage - please help on how to get it fully covered! My page (minus all the html which references variables from the class): <apex:page id="ApplicationFormPDF" ...
0
votes
2answers
28 views

Code coverage deployment

If there are four classes in the sandbox and first three classes have 100% code coverage and fourth class 0% code Coverage. Will the deployment will be success or fail
0
votes
1answer
45 views

Test classes for Scheduled Apex classes [duplicate]

Below I have shared the APEX code and the Test class code. I receive 100% code coverage, but I cannot grasp certain parts of it. Eg. The system.assert function - is it necessary? How do I know my test ...
-2
votes
1answer
31 views

Test Case for custom object [duplicate]

How to write test case for below method Custom Object : SAM_Request__c Global Variable :crossChargeInfoSetFlag , samAdminFlag , samTeamFlag boolean crossChargeInfoSetFlagMethod(SAM_Request__c ...
0
votes
0answers
19 views

Need help writing a test class for this Apex class [duplicate]

I am very new to Apex and was able to write this class to clone a record. However, when I tried to deploy it to Production I only had 70% code coverage. I think my next step is to write a test class ...
0
votes
0answers
96 views

test class coverage for process instance

Hi I am submitting record for approval in test class, and then again I am approving it. Still the status is showing as pending. Can anyone help here? public static testMethod void ContractTestMethod()...
0
votes
1answer
55 views

How to cover trigger.oldmap.get () in test class

public void updateAccessLevelsOnUpdate(final List<Opportunity> newOppList, Map<Id, Opportunity> oldOppMap){ if(Istrue == true){ try{ Map<Id, Id> ...
0
votes
2answers
50 views

Process Instance object test coverage

Hi I have a batch that works on process instance object, i am struck how to achieve test class coverage for this as ElapsedTimeInHours is a system field and when i am creating approval instance and ...
1
vote
1answer
131 views

sObject type 'FlowTestCoverage' is not supported

I am trying to run a query in the Developer Console to find the test coverage for a particular Flow I have created. However, I am getting the error: sObject type 'FlowTestCoverage' is not supported ...
0
votes
1answer
14 views

Query for Coverage of Flow

I am trying to find out the test coverage for a stand alone flow. I have a simple test class built, but I'm not sure where to run the coverage query. I came across the query below from the SFDC ...
-3
votes
1answer
23 views

Coverage code for remote action [duplicate]

Why the coverage code is 0? global with sharing class OutputControllerMap { @RemoteAction global static List<Output__c> findAll() { return [SELECT Id, Name, Project_Type__c,...
0
votes
0answers
66 views

Test Class for Dynamic SOQL [duplicate]

Pretty new with salesforce dev. So forgive me. I am doing a SOQL query and then updating records. The trick here is . I am grabbing my query from two custom fields which are in the Custom Settings . ...
2
votes
1answer
30 views

Jasmine or Mocha wrapper in Lightning Testing Service does not provide actual code coverage. How to measure JavaScript code coverage?

I have to test JavaScript code in lightning components with % code coverage. Lightning testing service report does not include code coverage information. Is there any way to measure JavaScript code ...
0
votes
1answer
129 views

Why is (Trigger.isInsert && Trigger.isAfter) not firing when running test class?

THE PROBLEM: My CustomObjectTrigger has a CustomObjectHandler class. I have code that is fired in the CustomObjectHandler class when the CustomObjectTrigger is fired by a new record that (isInsert &...
1
vote
0answers
25 views

How add a ServiceReport to a test class [duplicate]

trigger ServiceReporttoSA on ServiceReport (after insert) { for (ServiceReport SR: Trigger.new) { ServiceAppointment SA = [select Id FROM ServiceAppointment WHERE ID =:SR.parentId];...
0
votes
1answer
22 views

Trouble writing Help Class for JSON de

This test class is driving me crazy. I have can prove an array is passing through the class from the test class, but I can't seem to get code coverage. I did use the Json2Apex tool to build the class. ...
0
votes
1answer
35 views

Code coverage making mandatory [closed]

I would like to make code coverage mandatory during Sandbox to Sandbox deployment. How to achieve this? We have created two Sandbox named dev and QA and would want to make code coverage mandatory ...
1
vote
1answer
31 views

Test Class for the below code

i have written a test class for the following code, but it throwing a error like "Attempt to dereference a null object". can anyone please help me to overcome this. public class leadclass { ...
0
votes
3answers
34 views

Trying to increase code coverage for a trigger that deletes events

So I'm trying to write a test class to meet code coverage requirements to push up this trigger: trigger DeleteEventsOnCancellation on Case (after update) { for(Case c : system.trigger.new){ ...
0
votes
1answer
44 views

Code Coverage - Salesforce Connect Custom Adapter / Datasource.Connection Class

I am unable to find documentation on or get any code coverage for the customer adapter Apex Class (Datasource.Connection Class). For awareness, the external data source and customer adapter functions ...
1
vote
1answer
78 views

Creating Test Class for Einstein Bot Invocable Apex Class to Search Articles

I've created an Invocable Apex Class that allow us to search articles and return the resolution to the bot. The Apex class works as expected in the sandbox. However, I'm struggling to create a test ...