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
-2
votes
0answers
24 views

how can I write a test class for this code? [closed]

public with sharing class RentedBike { //public integer times; //public decimal decHours; // public decimal netprice; public Decimal custPrice {get;set;} public customer__c custinfo ...
2
votes
1answer
53 views

How to get code coverage report for LWC unit tests with JEST?

I was working on the unit test setup for Lightning Web Components with Jest and tried to figure out how to get a code coverage report but found nothing in the Docs. By running: sfdx-lwc-jest --...
-2
votes
0answers
32 views

How does a soql get covered in test class in a simple get method

I have an apex method which simply gets the record when passed with an Id. I have pasted the Apex and its test class.When I run the test class it covers just the method entry line and not the query ...
0
votes
1answer
11 views

Enterprise Territory Management (OppTerrAssignDefaultLogicFilter) Test Class Error

I am in the process of implementing the territories within Salesforce and was following the instructions and sample code from the help documents here: https://developer.salesforce.com/docs/atlas.en-us....
0
votes
2answers
38 views

Code Coverage for Catch block in test class?

I'm unable to cover the code coverage for catch block.Kindly help me to cover that code lines as well. Apex Class: public without sharing class ZTS_EU_Contact_populateCallDates { Map <id, ...
-1
votes
0answers
10 views

Test Unit Salesforce [duplicate]

Just want an idea on how will i create Test Unit for this scenario Classes for the Scenario Class CallOutAPI - Call Out External API Class CallOutAPI_Test - Test Unit for CallOut API using HTTP Mock ...
0
votes
0answers
24 views

Changeset validation failing with insufficient code coverage

I have an apex class with a platform event trigger that calls a queueable apex using System.enqueueJob() which in turns makes a web service callout in a try-catch block. The response returns by the ...
-3
votes
0answers
17 views

Test Coverage of Action Sent Email Message [duplicate]

I'm using the following Apex Class so when I create a case and then send an email through a Flow and there is a response to that email it will go back to the case. public class SendEmailMessage { ...
-1
votes
0answers
17 views

Classt Testing with catch exceptions [duplicate]

I already create a test class, but I think is too simpple, and my cover is 44% public class PortalProveedoresController { public boolean displayPopup {get; set;} public string idprov{get;set;} public ...
0
votes
1answer
20 views

How can I cover this contact owner assignment in test class after lead convert?

I have written a trigger helper method that converts to contact and associates the contact with an existing account. The contact owner becomes the owner of the account as shown in this snippet Now I ...
0
votes
1answer
87 views

Test Class Coverage for Trigger with oldMap

I have an Apex Trigger and Handler class on the Business Process object. When a lookup field (Financial_Planner__c) is updated on the Business Process, the system should query all Tasks associated to ...
-4
votes
1answer
34 views

Test class for setters & getters in virtual class [closed]

How to write test class to cover setters and getters in virtual class. Please help to get code coverage for the below class public virtual class TriggerHandlerExtension { public List<String&...
-4
votes
1answer
35 views

System.ListException: List index out of bounds: 0 In the Test Class

Hi i am getting List Index out of bounds error, can anyone check my test Class. Controller :- public class DOPdf { public list<Delivery_Order__c> delordr{get;set;} public Id getid{get;...
-2
votes
0answers
22 views

How to write apex test class for UserServicePresence trigger [duplicate]

We have created a trigger on UserServicePresence object and now we want to write apex test classes for it, For this below trigger we are trying to write an apex test class, we have tried but getting 0 ...
0
votes
2answers
35 views

Is this correct way of tackling Code Coverage scenarios?

If someone asks, there are n Apex classes with varying code coverage, some less than 75 & some greater than. What will happen while deployment? So the answer would be - (For Apex) all lines ...
0
votes
1answer
28 views

How to cover code coverage for the below Rest API where used for DOM Deserialization

MY Class:- @RestResource (urlmapping = '/UpdateBill/*') global without sharing class ApiUpdateClass{ @HttpPost global static void updateBill(){ try{ RestContext....
0
votes
1answer
27 views

How do I fix my error with test?

I need to cover some new functionality with tests, and for this I need to convert the lead in the test. I have two sandboxes (one is where we are developing; the second is for testing). In the first, ...
0
votes
2answers
69 views

How to increase code coverage for batch apex test class?

I have created test class for batch apex but it only covers 36% of code. How do I increase the coverage? Below is the test class that I have created. @isTest public class CloseOpportunityBatchTest { ...
0
votes
0answers
24 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 ...
-3
votes
1answer
50 views

Test class trigger.NewMap trigger.oldMap on opportunity [duplicate]

I need to write a test class on my OpportunityTriggerHandler and I'm having some difficulties to define how to construct the logic & scenarios in my test to test and the data to build in my test ...
3
votes
1answer
52 views

How to check Apex Code coverage for package extension?

I have two 2GMP packages: Baseline package and package Extension which depends on Baseline package. I have released Major version for the Baseline package and now I am trying to release Major version ...
-4
votes
1answer
46 views

How to cover the code coverage for Rest API Class [duplicate]

How to cover Code Coverage on test class for rest API, any help will be appreciated. My API Class:- @RestResource (urlmapping = '/UpdateBill/*') global without sharing class ApiUpdateClass{ ...
3
votes
2answers
123 views

Easy way to loop over Apex class member variables

So I am writing an API client for some third-party service. I get a response as JSON. now I am getting 100 fields as JSON responses but am consuming only 3 of those columns. I am using strict parsing ...
0
votes
1answer
28 views

Pointers on writing test class for ApexPages.StandardController Controller

I have the following Apex Class that I need to write a test class for. I've never done this before and rather new at this. Can someone offer pointers for this test class? public class ...
1
vote
1answer
93 views

sfdx force:source:deploy throws "INVALID_OPERATION: testLevel of NoTestRun cannot be used in production organizations"

I am trying to deploy config only changes (only a permission set change) and while running: sfdx force:source:deploy -x manifest/package.xml -u Prod I get the error: INVALID_OPERATION: testLevel of ...
0
votes
1answer
42 views

Why am I getting an Uncommitted Work Pending error when deploying?

I am unable to deploy this code because I am getting an error stating the following when a test class is run on it. This is the error : System.CalloutException: You have uncommitted work pending. ...
0
votes
3answers
58 views

Could I call the same method many times in the same test?

Is a bad practice call the same method many times in the same test method? Example: @isTest static void testSelectDevice{ List <Product2> device1 = new List<Product2>(); List <...
0
votes
1answer
36 views

Sandbox Testing and Deploying to Production

I am having an issue with getting my trigger and two classes from sandbox to production. I have one trigger that kicks off on an update to the account object that calls one of two classes to ...
0
votes
0answers
18 views

Need to write a test class for Http post class [duplicate]

@RestResource(urlMapping='/PioneerRxChangeEventListner/*') global without sharing class PioneerIntPharmacyApiClass{ @HttpPost global static ParentResponseWrapper doPost() { // variable ...
0
votes
1answer
83 views

How To Write Test Code Account Trigger Handler After Update

I wrote a trigger handler class on account to send an email if the code red field changes. If the code red field changes from true to false the email is sent and it blanks out certain fields on ...
0
votes
0answers
16 views

How to write a test for class that inserts records from CSV file? [duplicate]

Help me please, I don't know how to work with base64 type of VersionData public with sharing class UploadController { @AuraEnabled public static void csvFileRead(String contentDocumentId){ List&...
11
votes
3answers
2k views

Test Class Fraud - what's my responsibility? [closed]

In doing some work for a client, I discovered a class that has 1500 lines (out of 2500) consisting entirely of public static void AAA() { Decimal a = 0; a++;a++;a++;a++;a++;a++;a++;a++;...
0
votes
0answers
24 views

Help me to write unit test in salesforce [duplicate]

public with sharing class SalesPDRequestGenerator implements RequestGeneratorHandlerInterface { //Json generator private JSONRequestGenerator reqGen {get;set;} //context object ...
0
votes
1answer
36 views

Test class for Batch job having User object as scope with Custom field

I have a batch job with scope as List of User with Id,Name and one Custom field. Created data in test class with User but as scope getting different user with Name system. Not the which I have created ...
0
votes
0answers
18 views

No Coverage for CaseComment Trigger

I have a Trigger on CaseComment Object in my Org which has only one line of Code in It to call a static method from another apex class. But the trigger has 0% coverage. I have written a test Class to ...
0
votes
0answers
28 views

Unable to do code coverage, now my code coverage is 33% ,can anyone help for 75% [duplicate]

Extension Controller: public with sharing class CreateQuotePDFController { public list<QuoteLineItem> quoteLineItemsList{get;set;} public Id getid{get;set;} public Double ...
-1
votes
1answer
25 views

How to write test class for below Vf Page Controller [duplicate]

Class public with sharing class CreateQuotePDFController { public list<QuoteLineItem> quoteLineItemsList{get;set;} public Id getid{get;set;} public Double grandTotalTax{get;set;} ...
0
votes
1answer
52 views

Skip test coverage while deploying to sandboxes and production

I would like to deploy to my sandboxes and production a library called fflib; however, I do not want to include the test or run the test code, anyways, it is a library and we will never change the ...
0
votes
0answers
24 views

How to get coverage for return value from flow in test class?

I have a below class and test class. Flow called in this class call another apex action that get cases through integration for the Logged In user. I am not able to increase test coverage above 43%. ...
0
votes
0answers
22 views

How do I write a test class [duplicate]

I've recently written my first piece of apex and I've gone through the trailhead stuff about writing test classes but I don't really understand how I test each piece of the code. Can anyone give me ...
0
votes
1answer
35 views

Apex Test Class throwing NullPointerException

UPDATE NullPointerException error has been resolved (thanks @Adrian) INVALID_PERSON_ACCOUNT_OPERATION error was resolved by adding a RecTypeId variable Now I am confronted by an insert error: ...
-4
votes
1answer
48 views

Test class for apex with dynamic query

Hi I am new to Salesforce and I am trying to write test class for the Apex class.But I am not able to achieve it. Can someone help me? This is my apex class method. @AuraEnabled(cacheable=true) ...
0
votes
0answers
52 views

Test class for Invocable Method from Flow

I have been banging my head against the wall trying to work out how to write a test class that gets any coverage for this method, which takes values from a screenflow and returns a value back to the ...
-1
votes
1answer
36 views

Testing Code Coverage [duplicate]

I have only 73% code coverage, however, I've created multiple tests, all which pass. Here is the controller code: public class CaseController { public ApexPages.StandardController stdCntrlr {get; ...
0
votes
0answers
33 views

How to avoid SOQL Injection on the Below query [duplicate]

May I know, how I can avoid SOQL injections on the below query?? In the below query Filter can be anything like > or < or = Values are string one's. Functionality is working fine but injection ...
0
votes
1answer
58 views

Writing test class to change Inactive User to Queue

I'm a beginner APEX developer in a bit of a tricky spot. As we know, leads get assigned to sellers. However, sellers get fired from time to time causing them to become inactive users. The issue then ...
0
votes
1answer
30 views

Complicated Trigger Handler Need to Replicate Trigger Context Values

Let me begin by saying, I know that this could be significantly better code if using the Trigger.newMap and Trigger.oldMap I have run into a situation though where I need to reuse a class within a ...
0
votes
1answer
43 views

How can i test my Apex method

I am not sure how to write test class for this method. Any help would be greatly appreciated! @AuraEnabled(cacheable=true) public static List<Map<String, String>> getPickListValues() { ...
0
votes
0answers
26 views

Problem with Testing a New Quote Controller Extension

Updated Sep 10, 2021; see at end. I have written a VF New Quote page that uses a controller extension. The purpose of the extension is to initialize certain custom fields in the Quote and the ...
0
votes
0answers
25 views

Test class try catch on rest callout [duplicate]

So i am making post request and catch error by checking status code and by try catch too. And how can i test try catch block? I think mock response is useless here. So requst looks like: public void ...

1
2 3 4 5
24