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.

1
vote
1answer
38 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 ...
-1
votes
0answers
29 views

Class code coverage Issue [duplicate]

I have a problem in Test class my apex code is public class DeepcloneUser { public DeepcloneUser(ApexPages.StandardController stdController){ } @future Public static void ...
-2
votes
1answer
29 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
27 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
26 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> ...
-2
votes
0answers
26 views

Code Coverage Help - Sending Email

I created a class that I'd like to schedule with apex jobs to run on certain days. The class is working as intended, but i'm struggling with the test class. I'm not sure how I'm supposed to cover the ...
0
votes
2answers
32 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
33 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
11 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
0answers
24 views

Write test class for wrapper with else statement [duplicate]

I am having issues getting the converage for the apex class (newCom). This class gives users a list of record and they can click any number of cases to attach them to the parent (...
-3
votes
0answers
14 views

Unable to increase test coverage more than 62% .How to increase coveage [duplicate]

@isTest public class zTest_DisAppRequestReportCtrl { static testmethod void UnitTest1(){ Map<String,Schema.RecordTypeInfo> recordTypeInfo = Opportunity.sObjectType.getDescribe()....
-3
votes
1answer
18 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,...
-1
votes
0answers
23 views

Debug logs shows records in my list but the loop is still not covered [duplicate]

I have a trigger with the below apex class that works as expected. Right now it is covered 50%, debug logs show records in taskList but still couldn't understand how to resolve my coverage issue. Can ...
0
votes
0answers
34 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
22 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
49 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
24 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
20 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
34 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
30 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
28 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
31 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
53 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 ...
0
votes
2answers
20 views

Testing a trigger that is suppose to cover an failed check

I have a trigger on a custom Student object that is suppose to assign the lookup field Advisor based off of another look up field Gender. Basically my trigger goes: ... if (newStudent.Gender__c == ...
0
votes
1answer
31 views

Test Class Issue Standard set Controller Class

I write a test class to cover standard set controller class on account but i am not able to pass id. thats why not able cover code coverage. here is my code @IsTest public class ...
0
votes
1answer
30 views

need help on writing test class for controller

i have controller for vf page, i have written a test class. test class is having two methods where i am succesfully able to run the test for Autocal but for Save method i am getting following error ...
1
vote
1answer
22 views

Tests passing with zero code coverage [duplicate]

It seems like literally every test I write is passing with zero code coverage org wide. I've spent the past 2 days on and off reading forums, doing trails and debugging. Below is an example of one of ...
0
votes
1answer
16 views

Testing the Response of a PUT Method (or an response really)

I have a PUT method that I am attempting to test, but, like usual, APEX's ridiculous restrictions are causing roadblocks at every turn I make. My put method works fine when I am calling it from ...
0
votes
0answers
19 views

TestClass for @HttpGet to find locations based on geocodes [duplicate]

I am new to Apex coding and with lot of struggle I wrote the below apex class to find locations based on a Geocode custom object records. Now, I am having difficulties to write a testclass for the ...
1
vote
2answers
36 views

Deploy test for a SandboxRefreshScript

I'm trying to deploy a SandboxRefresh script to prod. One of the main things that script does is replicate the structure of Chatter groups we use so that I can then use Processes in my sandbox that ...
0
votes
1answer
51 views

I am not able to pass values into Custom settings fields in test classes?

There are Three custom objects Property__c Fields: Name, Region__c, site__c Deal__c Fields: Name, Type__c,Manager__c,Property__c Project__c Fields: Name, OwnerId,Deal__c // all objects has master ...
5
votes
1answer
77 views

Test coverage for a relative date method

Newbie coder here, so I could use some help with test coverage. I've got a class for creating test/training data in a sandbox. At the beginning of that class, I've got a couple of utility methods to ...
-2
votes
1answer
44 views

Test Class approach Help on Custom Object (Query and Update)

I have an Apex class on Custom Object Called QueueDistroHelper__c What I am basically doing is getting the Queue Id from a custom field(Related_Queue_Id__c) on the Custom object Querying all the ...
0
votes
0answers
35 views

Code coverage is low how to increase [duplicate]

I need to increase the code coverage to 75% for the following public with sharing class VIPortalHeaderController { // Fields private String channel; /** * Gets the channel. */ public ...
0
votes
1answer
36 views

Test Class for Comparable Wrapper class

I am trying to write a test class for a Comparable Wrapper with little success. The wrapper class pulls in two objects to make one single list. I have two issues... I don't know how to cover the ...
0
votes
0answers
32 views

Hello i am not able to get the result from this test class [duplicate]

I am trying to update the email in my Test class but it is not happening please help me. This is my class- global class PrepareSandboxPostCopy_Batch implements Database.Batchable { String query; ...
0
votes
2answers
57 views

Test Class - Error - Constructor not defined

Error - Constructor not defined: [PrepareSandboxPostCopy_Batch].() Test Class @isTest private class SandboxPostRefreshTestCase { static Testmethod void testSandboxPostCopyScript() { ...
0
votes
1answer
31 views

How to test the current logged in user in test class?

I need to cover the below method where I am using the current logged in user in the query. @Auraenabled public static User getUserInformation() { User user1 = new User(); user1 = [...
0
votes
1answer
33 views

Custom Controller Test Coverage

Having a bit of difficulty getting any code coverage for my custom controller. The goal of the controller is to display a list of opportunities in a list where the division of the user is the same as ...
0
votes
1answer
18 views

Unable to get code coverage for while traversing from parent to child in a SOQL query

In the following test class I am getting only 20% code coverage, and I am able to track it up to some level. Actually I am getting 100% code coverage before adding the following AND condition to the ...
7
votes
1answer
214 views

How do I increase my code coverage, or why can't I cover these lines?

This is a canonical question and answer developed by the community to help address common questions. If you've been directed here, or your question has been closed as a duplicate, please look through ...
0
votes
1answer
71 views

Getting to 100 percent code coverage on my trailhead module “Write Negative Tests Unit”

I seem to be stuck on this trailhead module or write negative tests unit, while I have 93 percent code coverage, I can't seem to get the code coverage to hit 100 percent at the "returnValue" piece ...
0
votes
1answer
42 views

How to test Exceptions (Query and DML) for ContentDocument?

I try to write wrong query, but I get just error un my test, not coverage. If I use try-catch in unit-test - no error and no coverage either. How to test it right? And how can I test here delete DML ...
0
votes
2answers
30 views

Code Coverage low even though I'm calling the method

I am coding an Apex Test Class for an Apex Class. I am have trouble understanding why some lines of code are being covered while others are not. I also don't understand why the if statement in my ...
6
votes
2answers
198 views

Is this test for callout wrong? How to make a bulk?

I wrote mock and test for callout, but I don't think it's right. I think I check wrong things with asserts and maybe call the same methods a few times, while have another ways to get 100%. Have I? I ...
1
vote
1answer
45 views

Batch Test Class works in Production, Fails in Test

I've started a new job and the test code coverage here is poor. I am working to improve this and one of the batch classes has coverage of 77% in production. This is now below the org % so I thought I'...
-2
votes
1answer
35 views

Cover execute method of a Batch class

first of all thank you for your time, i need some help to cover this batch class, right now the test class i will post bellow only covers the finish method and the get; set; . CLASS: global class ...
0
votes
1answer
20 views

Test Class for Visualforce Controller Test Class Coverage

I have a simple Visualforce page with a simple controller as follows public class EDU_CustomController_Getter { private String sortOrder = 'LastName'; //This is the getter method used to parse ...
2
votes
1answer
97 views

Need help to cover {get; set;} methods on a TestClass

i need some help on a TestClass as i said above, bellow i wil show you what the class looks like and the TestClass: APEX CLASS: public with sharing class DirectDebitController { public class ...