We’re rewarding the question askers & reputations are being recalculated! Read more.

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.

127 questions with no upvoted or accepted answers
Filter by
Sorted by
Tagged with
5
votes
0answers
148 views

My LWC test is not displaying code coverage

I have configured jest for Lightning web component test. My tests are running and passing but code coverage not displaying into output. Following is package.json file: - { "name": "my-...
4
votes
0answers
80 views

Perform a deployment and execute all tests with a flag to opt out of collecting code coverage

I'd like to perform a deployment and execute all tests with a flag to opt out of collecting code coverage. The goal is to speed up Apex test execution. I'm aware that we can do it manually by ...
4
votes
3answers
1k views

How to succesfully test AgentWork trigger?

I am using AgentWork trigger in my logic and I cannot achieve code coverage goal. Simple test method: Id cId = [SELECT Id From Case Where Subject = 'Case Subject'].Id; User u = [SELECT Id From User ...
3
votes
0answers
82 views

Salesforce Connect Custom Adapter test class

What is the correct way to approach testing Salesforce Connect custom adapters? Perhaps there is a unified approach to testing all of its parts, but specifically what is the approach for testing the ...
3
votes
1answer
217 views

sosl exception on searching with one character

On doing a sosl search with just one character search parameter, I am getting an exception. To overcome this i have used custom error message in the catch block.However I am unable to cover the catch ...
3
votes
2answers
638 views

85% code coverage yet upload fails

Hi I have 85% code coverage as stated by the developer console. All my classes have a test class and are above 75% with the only exception being my trigger at 66% coverage. The error is as follows: ...
2
votes
1answer
40 views

Multi currency test class

So we are planning to turn on multi currency for a customer org. Ive been reading up on the Apex changes required for queries, etc. But Im not sure how to handle our test classes. Our build org ...
2
votes
1answer
52 views

Apex Test Class: Populate parent relationship in a Master-Detail

I have the following code in a test class parent__c parent = new parent__c(); insert parent; child__c child = new child__c(); child.parent__c = parent.Id; insert child; In the DataBase, the ...
2
votes
0answers
1k views

Test class for community to get network id

i am facing problem with getting network id in test class, while executing visual force page, controller returns proper network id, when try to write a test class for this 'ClassNetwork' controller, ...
2
votes
0answers
345 views

OrderItem does not have ListPrice set in test, contrary to non-test

This is something I've run into and worked around, but it still annoys me because I have to write test specific things in my non-test code (and can't get to 100% coverage because of it). I can find ...
2
votes
0answers
153 views

Code coverage is 70% and I get a DUPLICATE_VALUE issue

Code coverage is 70% and when I dive into the problems I get a duplicate error. Please help I am new to writing triggers. Thank you ahead of time! Problem on several Lines Message: [object ...
2
votes
0answers
179 views

Data displaying in Overall Code Coverage section in developer console is not consistent

The data displaying in Overall Code Coverage section in developer console is not consistent, but displays incorrect code coverage sometimes 100% and sometimes with lesser number. For example, ...
2
votes
0answers
666 views

How to write test class for Default Account Team Members?

I am writing a test class which needs to cover code related to default account Team members. UserAccountTeamMember doesnt allow DML operation. Can you please let me know how to solve this issue in ...
1
vote
0answers
19 views

VS Code - Compare metadata in different orgs

The one thing that Eclipse IDE seemed to do well that I've not yet worked out in VS Code is comparing metadata in different orgs. Using VS Code, I know how to compare files which are in the same ...
1
vote
0answers
83 views

Test Class for TxnSecurity.EventCondition Implementing Class || Transaction Security 2.0

With Event Monitoring 2.0, I have successfully been able to create a class for Report Export Event. Can anyone assist with the Test Class, as all the field behind ReportEvent Big Object are non-...
1
vote
1answer
29 views

Do Apex tests (have to) run as part of the deployment when we deploy Processes and autolaunched Flows?

When you have enabled the setting 'deploy processes and flows as active' you need 75% of Processes and Autolaunched flows to have at least some Apex code coverage. The documentation on Running Apex ...
1
vote
0answers
20 views

Apex test class for covering site.login and it's exceptions

I'm currently having an issue in covering site.login and its exceptions in our test method. The exceptions are handled to cover the failed logins in our portal. This exception thrown from apex is ...
1
vote
1answer
61 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: ...
1
vote
0answers
129 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
0answers
135 views

Apex MyProfilePageController class bug

While trying to deploy apex changes to prod I receive an error for the MyProfilePageController class. I found https://developer.salesforce.com/forums/?id=906F000000099W9IAI. This is an issue from 2010,...
1
vote
1answer
240 views

Validation Errors While Saving Record(s) while executing test class

I am trying to execute a test class and getting this error : "Validation Errors While Saving Record(s)" There's no explanatory text or anything else which can help me to resolve this issue. We have ...
1
vote
0answers
219 views

Code Coverage 95% in sandbox and 47% in production for a class

I am at a loss right now why my code coverage is off for a particular class. I have @isTest(seeAllData = false) in my test class and I am creating my own data. I have also cloned a new sandbox from ...
1
vote
0answers
204 views

Apex test classes fail on HTTPResponse

I have some test classes that run decently until they hit something like HTTResponse res = h.send(req); Where I then get 'System.UnexpectedException: Script-thrown exception'. I make a few ...
1
vote
0answers
86 views

Testing @RemoteAction method with mock data inserted in factory

I'm struggling a little bit with accessing data which has been inserted through factory method in my RemoteAction method. Here is a code of RemoteAction method : @RemoteAction global static ...
1
vote
0answers
110 views

Apex ContentDistribution in testmethod

For covering an apex class I need to create ContentVersion + ContentDocumentLink + ContentDistribution I succeeded in creating the first 2 but failed with the ContentDistribution (Internal Salesforce ...
1
vote
1answer
284 views

Test Class coverage for UserAccountTeamMember

I have a test class block which I am unable to cover as it queries UserAccountTeamMember object for a default account team member. I tried to insert record in that object through test class but DML is ...
1
vote
1answer
254 views

How to write a test class for covering Bundle product?

I am trying to cover a class in which I have below condition which contains one variable called SBQQ__Bundle__c available on QuoteLine Object of steel brick CPQ. I have tried to investigate regarding ...
1
vote
2answers
115 views

when user deactivate assign case to queue in test class

public class Helper { @future public static void dummyUsers(Set<Id> userIds) { }
1
vote
0answers
178 views

A lower code coverage problem when trying to deploy

All my apex classes have more than 90% code coverage. But, when I am trying to deploy them, it is showing I have 59% code coverage. How to solve this issue. I have run all test, & check all apex ...
1
vote
1answer
221 views

Wrote a trigger to prevent record deletion, now need help with test class

I'm a newbie when it comes to writing triggers and test classes. I've written a trigger that prevents the deletion of a record on a custom object, System_Integration__c, when a date field (...
1
vote
0answers
22 views

Enforce DML statement to be failed within a batch

I am trying to make a DML statement in a batch to be failed. The reason for this is that I have logic executed in my batch in case the DML failed for some records. I would like to test it and get the ...
1
vote
0answers
176 views

Test Class with @invocableMethod

I wrote an Apex Class (with the help of some code I found on the internet, because i'm not a developer) to help automatically post some content to chatter with @mention. This Class had a @...
1
vote
1answer
56 views

Test Code for Conditional Event Deletion is not running expected lines

I'm having some problems with a test class and I honestly can't figure out why. Maybe I've been staring at it for too long, but in any case - would appreciate if someone can tell me where I've gone ...
1
vote
0answers
100 views

How to write test cases for Salesforce application to check its code coverage with an example of making a test case for a code example?

I want to write test classes for my apex code to get code coverage. I have seen this documentation to get idea about test classes but I am not clear about test classes w.r.t my apex classes. So, I am ...
1
vote
1answer
107 views

how to identify correct code coverage in SalesForce?

I am getting issue with code coverage percentage. In my dev org it is showing 84% but when I am trying to create package then it is showing 74% and I am not able to create package. I have cleaned up ...
1
vote
0answers
286 views

Incorrect code coverage in developer console

I have an apex class called RelationshipTreeController (RTC for short) and a test class called RelationshipTreeControllerTest (RTCT for short). I have written a test method that calls the search() ...
1
vote
0answers
1k views

Assistance with a Test Class to increase code coverage

This is a follow up to my previous question of Is there anyway to deactivate a trigger in Prod when the minumum code coverage is not met. I am not an apex developer and I am the only SFDC Admin at my ...
1
vote
0answers
190 views

Issue: Salesforce UI, Developer Console and Eclipse IDE shows different code coverage for the same class. Is anyone experienced this?

This is very much confusing and hard to believe which one is valid. Below screen shot describes the issue as the code coverage for one of the class "OpenDocumentsController" showing 100% (179/179) in ...
1
vote
0answers
179 views

why test coverage includes all classes and triggers when creating an unmanaged package with selected classes?

Trying to create an unmanaged package with few classes but i am getting the following error when i try to "Upload". There are other Apex classes and triggers in my free dev org for which i do not want ...
1
vote
0answers
305 views

See the code coverage of my package without uploading it

I have a packaging org of a managed package and only 60% of its classes are actually part of my managed package. How or where can I check the code coverage of only those packaged classes without ...
0
votes
0answers
17 views

How do you create Resource Calendar in Apex for test class?

I need to have a Resource Calendar in Apex test class. I tried to do below in Test Class. List<Calendar> lc = new List<Calendar>(); for(Account acc :listAcc) Calendar c =...
0
votes
0answers
8 views

UI Theme Detection: Unit test code coverage

Since Winter '16, we have had the ability to add conditional logic to our Apex controllers and Visualforce pages based on the UI theme the user is currently working with (i.e. Classic vs. Lightning ...
0
votes
1answer
23 views

Question Concerning making a Test class for a before update trigger that sends an email

I'm currently trying to make a test for an apex trigger that sends an email if a certain donation field has been changed(before this I tried using a workflow but for some reason it did not work). From ...
0
votes
2answers
51 views

mock test class and test class for 2 classes

I have 2 class A and B. A has code for Http Callout and from B we are calling A's class method which has callout code. So should we write mock test class for A only or do we have to write mock test ...
0
votes
1answer
30 views

Test class not working for more than two or three methods in same class it fails for other two methods only one method covers

public with sharing class TransactionsalSecurity { @AuraEnabled public static List<ReportEvent> TransactionalSecurityToday() { return [SELECT Name, QueriedEntities, Format, ...
0
votes
0answers
29 views

How to validate Old and New Values of ContactHistory in Test Class

I have an apex class which looks for the old and new values of contacthistory. I am writing a test class for this, but could not write data to Oldvalue and Newvalue. I also tried updating the field ...
0
votes
0answers
15 views

Test Class Code coverage Improvement

My test class @testSetup static void createTestRecords() { User thisUser = [ select Id from User where Id = :UserInfo.getUserId() ]; System.runAs( thisUser) { //creating User ...
0
votes
2answers
58 views

How to simulate visualforce page button in test class in order to deploy it?

Hi I have an Apex class which is called/invoked from a custom button called "desiredLocationsPage" , I have created the custom button in production like below; I have tested my test class in sandbox ...
0
votes
0answers
34 views

Deployment of apex code to production

I am trying to get rid of some old apex code in a Salesforce org. There are few test classes on production org which are broken because 1) they were written a few years back with old API version or 2) ...
0
votes
0answers
34 views

Cover return Null in test class for code coverage

Here is my test class and class. global class ACN_NavigationImplementationTemplate implements ACN_NavigationProviderService { global ACN_NavigationLibrary.NavigationList GetNavigationList (...