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.

209 questions with no upvoted or accepted answers
Filter by
Sorted by
Tagged with
4 votes
0 answers
359 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 ...
Matthew Souther's user avatar
4 votes
0 answers
116 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 ...
Pablo Fischer's user avatar
3 votes
0 answers
128 views

Platform Event triggers for Subscription Management events cannot be covered by unit tests

As part of the Subscription Management license, certain platform events are fired when an Asset is updated, an Invoice is processed etc. For example the CreateAssetOrderEvent. Currently we are using ...
shooting at the moon's user avatar
3 votes
0 answers
341 views

What is a typical JavaScript code coverage for LWCs (Lightning Web Components) that are adequately tested via JEST?

I know this might get closed as being a matter of opinion, but as long as those opinions are based on actual experience, such answers are valuable to me, particularly if they are somewhat consistent. ...
Keith C's user avatar
  • 136k
3 votes
0 answers
512 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 ...
Bigears's user avatar
  • 1,131
3 votes
0 answers
279 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 ...
moth's user avatar
  • 454
3 votes
1 answer
588 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 ...
starhunter's user avatar
2 votes
0 answers
964 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-...
Varun SFDC's user avatar
2 votes
1 answer
244 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 ...
discodowney's user avatar
2 votes
0 answers
438 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 ...
george thomas's user avatar
2 votes
0 answers
611 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 ...
Legolas's user avatar
  • 383
2 votes
0 answers
177 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 ...
Nate's user avatar
  • 137
2 votes
0 answers
201 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, ...
Bforce's user avatar
  • 6,828
2 votes
0 answers
744 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 ...
Keepcalmncode's user avatar
1 vote
0 answers
82 views

Manually loading apex test code coverage from sfdx command into vsCode

Whenever I run tests through vsCode, the tests take very long time to complete (a single test could take up >10 min or they time out with the "Your request exceeded the time limit for ...
Luis M Valenzuela's user avatar
1 vote
1 answer
123 views

Blob is not a valid UTF-8 string error in test class though am converting base64 into normal text in apex class

Am getting case subject "?utf-8?b?QW5vbWFseSBkZXRIY3Rpb24g4oCTIERFIFNIQVc?=" In this format from third party system. So am converting into string as below: String s= case.subject; String s1 ...
Sweetie's user avatar
  • 11
1 vote
0 answers
47 views

Why does the Dev Console stop reporting All Tests coverage?

I have wondered this for a while now - sometimes when using the developer console, and running tests, the console stops listing the percentage of coverage next to "All Tests" in the upper ...
number41's user avatar
  • 948
1 vote
0 answers
242 views

Write a test class for dynamically created custom fields

I have a code whose logic revolves around the availability of certain fields on the org. I am checking this with if(Schema.SObjectType.CustomObject__c.fields.getMap().keySet().contains('customField__c'...
sandroid's user avatar
1 vote
0 answers
69 views

Need help with test class that mimics user input on visualforce page

We have a signature capture box on a visualforce page that was created long before I was around. I'm just changing it from being saved on the old Attachments object. For the life of me, I can't find ...
ad_rey's user avatar
  • 59
1 vote
0 answers
384 views

Deactivating a Trigger code coverage

I am trying to deactivate a trigger in sandbox and push to production but an not able to validate/deploy in production due to a code coverage error. I have tried both deactivating the trigger and ...
Patrick O'Donnell's user avatar
1 vote
0 answers
634 views

IsCustomerPortal field to be covered in test class

SELECT Id,IsCustomerPortal, Retailer_Stage__c, CreatedDate,Registration_Date__c FROM Account WHERE RecordType.DeveloperName = 'Distributor' AND BillingCountry = 'India' AND **IsCustomerPortal** ...
sumanth sumanth's user avatar
1 vote
0 answers
58 views

Newbie needing help writing a test class for an invocable method

With a lot of help from this forum and the developer forum, I got my first invocable method to work but now I am stuck on writing the test class for it. Here's my invocable method and the attempt at a ...
Nicolai Nonnenbroich's user avatar
1 vote
1 answer
575 views

Issue with testing callback of continuation - no method on provided controller type

I have an apex class that is using a chained continuation concept. My class functions fine and appears to be making all of the callouts as expected. Now I am trying to write my test class for code ...
SBB's user avatar
  • 173
1 vote
0 answers
370 views

Flow Interview on Invocable Process - how to get test coverage

I’m looking at a list of flows that don’t currently have code coverage obtained by running the following Tooling API SOQL: SELECT Definition.DeveloperName FROM Flow WHERE Status = 'Active' AND (...
Chris Campbell's user avatar
1 vote
0 answers
1k views

Overall code coverage showing zero after running test class

Every now and then I encounter the following issue after I run my test classes, they all marked as completed and pass, however the class in the section Overall code coverage shows as 0 (some of them ...
manza's user avatar
  • 1,953
1 vote
0 answers
587 views

Even with KnowledgeUser I get: Be sure the action is valid for the current state of the article, and that you have permission to perform it, exception

I have the below test class: @isTest public static void batchManagementDraftTest() { User u = TestDataFactory.createUserWithRoleLeader(); User u2 = TestDataFactory....
nSv23's user avatar
  • 544
1 vote
0 answers
257 views

Test class for Einstein OCR service

We are hitting Einstein OCR to predict an image. When we tried to write test class for it we are always getting this error in developer console. Go to Setup and Configuration on the Einstein Admin tab ...
SFDC-Beginner's user avatar
1 vote
0 answers
116 views

Test Class on an Update Trigger

This is my very first trigger. It does exactly what I intended it to do. trigger FirmAssociationTrigger on Opportunity (before update) { for(Opportunity a : Trigger.new) { // Get the ...
APEX Newbs's user avatar
1 vote
1 answer
290 views

Why code coverage result is different when we run it from CLI and Salesforce

We are working on SonarQube code coverage, We are using Salesforce CLI for generating the code coverage result and we are importing that result in the SonarQube. We see that there is a difference in ...
Spande's user avatar
  • 61
1 vote
1 answer
493 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> { ...
Asel Vazirova's user avatar
1 vote
0 answers
537 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 ...
S.B.'s user avatar
  • 2,069
1 vote
1 answer
89 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 ...
Furkan Kuyular's user avatar
1 vote
1 answer
1k 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 ...
abd3721's user avatar
  • 2,152
1 vote
1 answer
795 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: ...
SanSFDC's user avatar
  • 11
1 vote
0 answers
636 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,...
Gabriel M's user avatar
  • 106
1 vote
1 answer
586 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 ...
user54240's user avatar
1 vote
0 answers
593 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 ...
DerrickE's user avatar
1 vote
0 answers
582 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 ...
JimKasper99's user avatar
1 vote
0 answers
152 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 ...
stosik's user avatar
  • 11
1 vote
1 answer
859 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 ...
Sharma_raj's user avatar
1 vote
2 answers
359 views

when user deactivate assign case to queue in test class

public class Helper { @future public static void dummyUsers(Set<Id> userIds) { }
cloudZigZag's user avatar
  • 1,366
1 vote
0 answers
409 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 ...
Tanmoy Das's user avatar
1 vote
1 answer
560 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 (...
J. S.'s user avatar
  • 11
1 vote
0 answers
31 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 ...
sfdcdev's user avatar
  • 389
1 vote
0 answers
362 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 @...
Cesar Covre Batista's user avatar
1 vote
1 answer
90 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 ...
Morgan Marchese's user avatar
1 vote
0 answers
125 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 ...
Khawaja M. Awais's user avatar
1 vote
1 answer
116 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 ...
Sanjay Kharwar's user avatar
1 vote
0 answers
310 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() ...
Louis Pujol's user avatar
  • 1,235
1 vote
0 answers
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 ...
user7417's user avatar
  • 311

1
2 3 4 5