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.

161 questions with no upvoted or accepted answers
Filter by
Sorted by
Tagged with
5
votes
0answers
670 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
89 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 ...
3
votes
0answers
339 views

How to write an Apex test for a Process Builder's scheduled actions?

I'm creating test coverage code for an autolaunched flow to push to production. Using the Tooling API in developer console, I can see that I almost have 50% coverage 4/11 elements covered (as seen ...
3
votes
0answers
112 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
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, ...
3
votes
1answer
319 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 ...
2
votes
0answers
137 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 ...
2
votes
0answers
238 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-...
2
votes
1answer
122 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
235 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
460 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
154 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
185 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
686 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
55 views

System.SObjectException: Field is not writeable:

We have the following code and Apex Test Class, and for some reason during Apex Test Execution (Developer Console-->Run Test) it is throwing the following error message below. Any ideas why the ...
1
vote
2answers
320 views

Test Class for the Apex Class with try Catch block fails

I am trying to write a test class for the Apex Class with try - catch block and this is my first time coding test classes. The Apex Class is like below which has trycatch public class ...
1
vote
1answer
43 views

Test Class for Apex Batch Job generating Invoices covers only 38%

Please help me to finish my Test Class for the following Batch Job generating Invoice creation. Apex Batch Job global class InvoiceGenerateBatchJob implements Database.Batchable<SObject> { ...
1
vote
0answers
98 views

How to get code coverage with logic based on screen flow variables?

I am trying to get code coverage to deploy a class that depends on variables set in a screen flow. I've read various articles saying it's not possible to get coverage for screen flows. Is this ...
1
vote
1answer
38 views

Can i improve code coverage for loop in batch apex

Firstly I wanna protect my organization code coverage, My scenario is as follows; I wrote 1 batch apex process, for calculate cycleTime to every products, am getting %80 covarage with this code but ...
1
vote
0answers
372 views

Need Test Classes for AutocreatedConfigSelfReg and AutocreatedDiscLoginHandler

I'm an admin and beginner developer who was setting up a community and thought that the login discovery page was a great user experience. Without due-diligence, I went ahead and selected the "create a ...
1
vote
0answers
76 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
1answer
147 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
72 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
164 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
199 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
341 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
309 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
278 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
100 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
233 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
402 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
382 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
162 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
240 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
279 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
24 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
208 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
65 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
101 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
108 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
292 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
182 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
311 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
1answer
14 views

Calling component controller through VF page by passing id as parameter

I have to write a test class for a controller . It is a component's controller. The component is called in a VF page in below fashion <apex:page standardController="Obj1__c" extensions=...
0
votes
1answer
29 views

Class having 100% code coverage on UAT can't be deployed due to 63% during production deployment text check

I have apex class SalesProcess which has 100% code coverage in UAT. But during deployment to Production I get error saying that it is only 63 % covered. No other error just that. The class: public ...
0
votes
1answer
28 views

ApexOrgWideCoverage history

The below tooling API returns the org wide coverage, it is working fine . do we know how to get teh history of the coverage. say how is teh coverage in the last week and to see over the period? SELECT+...
0
votes
0answers
46 views

INSUFFICIENT_ACCESS_ON_CROSS_REFERENCE_ENTITY : [NetworkId]

I've written a simple trigger to enforce our Community users not to delete files. Currently, I'm facing an issue in getting test coverage for deployment. Trigger trigger ContentDocumentTrigger on ...
0
votes
0answers
24 views

Getting an error while creating unlocked package with --codecoverage option in salesforce

As per the current requirement new versions of packages can be created only buy running the sfdx force:package:version:create with --codecoverage option, however I am getting an exception related to ...