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.

Filter by
Sorted by
Tagged with
0
votes
0answers
17 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-...
0
votes
0answers
13 views

How to write help class for the below trigger [duplicate]

trigger ActiveCountContactOnAccount on Contact (after INSERT, after UPDATE, after DELETE , after UNDELETE) { Set <Id> accountIds = new Set <Id>(); List <Account> lstAccountsToUpdate =...
5
votes
0answers
37 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-...
0
votes
1answer
41 views

Batch Test class not calling execute method [duplicate]

I have created below batch apex class. I have also created test class for this. But this test class is only covering 27% of batch apex class. Also, it is not calling execute method of batch apex class....
4
votes
3answers
98 views

How to mock ApexTestQueueItem, AsyncApexJob, and ApexTestResult for test coverage?

I'm currently working on a set of classes that do the following: A class that when instantiated and executed, queues all Test classes in Apex to run by inserting ApexTestQueueItems. I call this one ...
0
votes
2answers
26 views

Overall Code Coverage including unrelated classes as well

I have a sandbox org where I've created a trigger that calls another class containing a future method for final HTTP request. I have also created a test class and MockHttpRequest for it which is able ...
0
votes
2answers
40 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 ...
8
votes
1answer
99 views

Visual Studio Code Apex class code coverage colors

I'm looking at the code coverage results from a recent run of all the tests in an org, and I'm not sure what all the colors represent. The green and red seem fairly self explanatory: Green - covered ...
-3
votes
2answers
51 views

How to convert String to list<object> for a test class [closed]

I have a Json getting it in Aura Controller, and for test class, I am mimicking the Json into a string . Original JSON = [{"subid":"a4wgwe00000DfDRAA0","totalgs":"25","Revenue":"17"},{"subid":"...
0
votes
1answer
26 views

Test Class Coverage for If Statements and calling class?

I have a controller that grabs records based on a user's email. Works fine but when it comes to the test class it does not cover these if statement: for(Order__c o: OrderDAO.selectOrder(uEmail){ ...
-1
votes
0answers
22 views

I am able to cover the class upto 32% only can U help me o cover more [duplicate]

ApexClass: public class opportunityApprovalHistoryController{ public string serverURL {get;set;} public ProcessInstanceWorkitem piw {get;set;} public boolean IsdelegatedUserId {get;set;} ...
0
votes
0answers
32 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
19 views

How to write test class for the below class. I tried alot but it not covering [duplicate]

public class LeadAssignment { public Set<String> nullParamsSet; public LeadAssignment(){ nullParamsSet = new Set<String>(); for (NullParameters__c np : ...
1
vote
2answers
33 views

Question about making a test class for my before update trigger that uses custom objects and uploading via change set

I’m new to apex and I am currently trying to upload my first trigger to production from my sandbox using change sets .Its purpose Is to update the date field of the site object with the most recent ...
1
vote
0answers
14 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
25 views

test class for apex class creating multiple object records [duplicate]

Can anyone helps me out in writing the test class for below apex class. I know that I should not post it here asking for this kind of questions but as I am new to apex and I need to deploy so I was ...
1
vote
2answers
36 views

Trigger Code Coverage with if condition

I am creating a test class for the giving trigger but because of the if conditions I am not getting code coverage above 50%. Please help me out for the same. This is a trigger class : trigger ...
1
vote
1answer
11 views

I have Case handler class and I am new to test classes and I am struck, Could you please help me out on this [duplicate]

Here is the CaseHandler Class public class CaseHandler { public static void onCaseInsertOrUpdate(List<Case> newCases, Map<Id, Case> oldMap){ List<Id> acctIds = new List&...
-1
votes
0answers
12 views

Visualforce Controller Test Class [duplicate]

I have the following method in my custom controller. I'm only able to get 68% coverage in testing. In the following method I'm not getting coverage for the permission set list I'm using. This is also ...
-2
votes
0answers
11 views

Test class not working for below code [duplicate]

My code coverage is only 59% for the apex class I am not sure how to make it to 100% everytime it fails Attached is my code for reference Apex class public class Describe { public Map <String, ...
2
votes
1answer
42 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 ...
0
votes
1answer
25 views

Quicker way to get covered lines of a class

I am working on a unit test of a class in developer console. My target is to achieve a certain level of coverage. I am on edge of reaching my coverage target, so I need to know the number of lines ...
0
votes
0answers
15 views

Test class not working with code coverage [duplicate]

We write following class for describing object types. public class Describe { public Map <String, Schema.SObjectType> schemaMap = Schema.getGlobalDescribe(); public string renderAsdoc{...
0
votes
0answers
23 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 (...
0
votes
0answers
16 views

Apex Trigger Code Coverage Error for Triggered Send with Marketing Cloud Connect

I've read several threads and documentation related to this issue but can't seem to figure out what I need to do differently. I'm trying to activate triggered sends via Marketing Cloud Connect in ...
-1
votes
1answer
22 views

Need help in writing Test Class for Rest API Class [duplicate]

I have a REST API class which updates the user status in external system when the user status is changed in Salesforce. Below is the code public class AccUpdateController { @future(callout=true) ...
0
votes
1answer
24 views

Unmanaged package error

I have created a lightning component and want to create a package for that i wrote a test class for apex class coverage too which is showing 100% code coverage but when iam trying to upload the aura ...
0
votes
1answer
29 views

0% coverage on trigger [duplicate]

I have a working trigger that I'm starting to build my test class for. I've done a few lines and ran a test to make sure it's working as it should and everything seems okay, except the trigger itself ...
1
vote
1answer
23 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 ...
0
votes
1answer
17 views

How to cover piece of code using test class which is checking if its sandbox or Production

I have below Peice of code which is chekcing if its sandbox then run If part else run Else part if(runningInASandbox()) { return getSsoRedirect('one', startUrl, ...
0
votes
0answers
11 views

test class file previewer [duplicate]

I need help in writing the test class for a file previewer component. This component has two apex classes. Lightning component <!--aura attributes--> <aura:attribute name="...
6
votes
3answers
120 views

Testing an Apex batch method execute() exception incrementing NumberOfErrors in the finish() method

I have a batch job that runs over a SOQL query locator. Occasionally there will be an unhandled exception in the execute() method. Later on in the finish() method I check the corresponding ...
1
vote
0answers
17 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
26 views

Test class for current user and get set member variable?

I have following class: public without sharing class exampleController{ public static User currentUser { get { if(currentUser == null){ currentUser = [SELECT ...
0
votes
1answer
18 views

Unable to cover code [duplicate]

I am Unable to cover the code. I have inserted all the possible data in test class still the code coverage is 35%. Can someone please help? Apex class : global class ProductCustomController { ...
0
votes
2answers
39 views

IntelliJ not showing code coverage for class

I'm having trouble with identifying code coverage in IntelliJ for my Apex class. On the side of my project, after activating "Run with Coverage," the percentage of lines covered is shown: But the ...
0
votes
1answer
16 views

Does change set validation run tests within the change set or those already in the org?

When you deploy an inbound change set with apex classes and their respective test classes in the change set, does the validation run tests that are in the change set or those already in the org? So ...
0
votes
0answers
33 views

need test class for apex class with 75% Percentage Code Coverage, now 69% [duplicate]

Hi i create the class to generate document: public with sharing class GenerateDocumentApiHandler { //here is what i failed public Static GenerateResult generateDocId(String ...
0
votes
1answer
24 views

Exception in test class while executing batch class

I'm getting the following exception while executing batch class from text class System.UnexpectedException: No more than one executeBatch can be called from within a test method. Please make sure ...
0
votes
0answers
31 views

force:mdapi:deploy fails with RunLocalTests + test coverage > 75%

As other people (see Code Coverage during sfdx force:mdapi:deploy) I am unable to move code using sfdx force:mdapi:deploy to another org due to Apex Class Coverage. But as @sfdcfox notes out: If ...
0
votes
0answers
26 views

Httpresponse is not getting coverd in testclass

My response was stored in static resource and I am setting fake response by staticresource method to class but my Httpresponce is not getting covered in test. @isTest global class SmartSheetUtil_Test ...
0
votes
1answer
42 views

How to Code coverage for List of Single email content in Apex Class

Apex method: webservice static boolean sendEmail(id opptyId, id duplicateid) { //Approval Email Body content PageReference SEmail = Page.Sales_ApprovalPage; SEmail.getParameters().put('...
-1
votes
1answer
32 views

How to cover the SETENDPOINT kind of lines in test class [duplicate]

**APEX-CLASS** public class TriggerFlodataWorkflowController { public string inputIds{get;set;} public List<String> selectedNames{get;set;} public List<String> selectedIds{get;set;} ...
0
votes
1answer
49 views

Code Coverage 83% in production 75% in sandbox - can't deploy

In production, code coverage is showing 83%. In sandbox, it is showing 75%. I have just 1 apex class and associated test class I am trying to deploy to production, but it fails saying only 30% ...
2
votes
1answer
24 views

Standard User profile gives error for delete task trigger testclass

I have trigger to stop users to delete task except if profile is "System Administrator". Trigger : trigger TaskTrigger on Task (before delete) { if(Trigger.isBefore && Trigger.isDelete){...
-2
votes
1answer
31 views

please help me with the test class of this part of controller class [duplicate]

Part of controller class global class ApexSchedulerCreateSearchescl { static List<RecordType> listrt; static String zipcode; static ID state; static string ...
0
votes
0answers
35 views

Getting error while running test class-System.NoAccessException: Set up My Domain to access this page

i am into the situation where from Developer console my test class is getting passed but from UI -its with error 'System.NoAccessException: Set up My Domain to access this page.' Please suggest. ...
1
vote
1answer
41 views

Profiling system for “dead” code

I recently inherited a mature SFDC organization. It was established back in 2014 but was poorly maintained. There is very little documentation to support the business or system requirements. Any ...
0
votes
0answers
36 views

Writing test Class - Code Coverage 0% [duplicate]

Working on creating a test class for my class in my sandbox and I am receiving a code coverage 0% in the dev console. The console isn't highlightning the lines that need to be covered in red either. ...
0
votes
1answer
40 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....