Skip to main content
New
Stack Overflow Jobs powered by Indeed: A job site that puts thousands of tech jobs at your fingertips (U.S. only). Search jobs

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
1 answer
42 views

No Code coverage for excuted code

Our unit test shows the code is being executed as shown below at line 65 but 0% code coverage detected: However, deployment failed reporting 0% code coverage for Exceptions class:
Smegal's user avatar
  • 31
1 vote
1 answer
41 views

Unable to lock row or deadlock issue

We have over 200 test methods in the org and since I started creating some test classes for my own Sandbox I have ran into issues with the following error but may vary by method: System.DmlException: ...
MrKnudz's user avatar
  • 13
-1 votes
2 answers
1k views

Expected double-quoted property name in JSON at position 6025 (line 1 column 6026)

I'm trying to view code coverage using my vscode but after running test if I enter in the class I was testing, I have this error and I can't see the code coverage and the percentage anymore. Thx in ...
Papa Ibrahima SOW's user avatar
2 votes
1 answer
71 views

OpportunityFieldHistory in Apex test class (field tracking - NewValue)

i'm new to learning about Apex Test Class. I have business logic that needs to check the value of 'OpportunityFieldHistory' == 'ClosedWon' in a class to create a record (Contract). I'm making a test ...
Aparicio Jr's user avatar
1 vote
0 answers
30 views

Seeing Code Coverage for 2GP Managed Package Version

I'm developing a 2nd-Generation Managed Package and working on releasing a new version. Our package depends on one "core" package which is under the same namespace. Note: we develop the &...
Dylan Bowman's user avatar
0 votes
2 answers
46 views

Test Class coverage on execute method of Batch Apex which is Scheduled to run at specific interval of time

I have a Batch class, which queries Lead records that were created 1 day before. I have created a custom Label 'More_Than_1_days' which has the value 1. I was using this custom label in that batch ...
Mohd hasim's user avatar
-2 votes
1 answer
37 views

System.QueryException: List has no rows for assignment to SObject - In Test Class

I'm Getting an error in running of Test Class but the functionality in class working as expected: System.QueryException: List has no rows for assignment to SObject The below query is giving an error:...
sekhar's user avatar
  • 19
0 votes
1 answer
462 views

How do I get Apex Code Coverage in Visual Studio Code to show color highlighting and percentage after running a TestSuite?

I am using the most updated SF plugin, Visual Studio Code and sf-cli against our internal sandbox environment. I have an Apex class that has tests in multiple files. I would like to run a test suite ...
Shaun's user avatar
  • 151
0 votes
1 answer
91 views

Do mock classes need @IsTest?

Should mock classes always be annotated with @IsTest? Are the reasons not to annotate them? The reason that I'm asking is that I stumbled upon a mock class with a custom constructor for testing that ...
Semmel's user avatar
  • 2,497
0 votes
1 answer
24 views

How can I cover the Exception in this code in Test coverage(test class)? I did everything but my knowledge is not enough please help me :(

public with sharing class SampleClass {//EV GS R-3209 07122021 @AuraEnabled public static String insertCase() { String mReqRTid = Schema.SObjectType.Case....
Jay Locker's user avatar
0 votes
0 answers
26 views

Hi..Need help to cover the ContentDocumentLink part in uploadFile2 method and uploadFile method in @InvocableMethod. I mentioned as need to cover part [duplicate]

Main Class: global class FileUploadController { public static void uploadFile2(Id parentId, String fileName, String fileContent) { // Initialize response object Map<String, ...
Arun Pandiyan's user avatar
0 votes
1 answer
30 views

I trying to write test class for a Apex class. I covered the try statement where I couldn't cover the catch statement. Please help me to resolve

Main Class: public class PrintJobPDFController { @AuraEnabled public static List<String> getPDFprint(string recordId) { try{ System.debug('recordId'+recordId); ...
Arun Pandiyan's user avatar
0 votes
0 answers
89 views

Test Methods With No Assert result

I'm using the Salesforce code scanner to validate my package and am seeing a lot of "Test Methods With No Assert result" messages for methods that do contain asserts, and test methods run ...
ravent's user avatar
  • 35
0 votes
0 answers
66 views

Error message on account insertion bypassing duplication

Account duplication rule is active on my salesforce for name of account. When i click approved from an one object an account is created, i wrote code for this using apex class. If there is no ...
user139696's user avatar
0 votes
1 answer
58 views

"No test methods found in the Apex code included in the package." But coverage is at 100%?

I have created a LWC component, it has 1 Apex class that is test covered at 100%. However when I try to create my package, it fails saying "No test methods found in the Apex code included in the ...
SamPerron's user avatar
0 votes
1 answer
33 views

Issue with Empty Results in ApexCodeCoverageAggregate after Validate with RunTest via ANT

I'm encountering an issue while trying to retrieve Apex class coverage after running a Validate with RunTest via ANT in Salesforce. The problem arises because, for certain classes, the coverage report ...
Emanuele Alfano's user avatar
0 votes
0 answers
23 views

Wrote a Future method where Testcoverage is not 100% [duplicate]

Testcoverage class : @isTest public class AccountCalcultorTest { @isTest public static void contactcalculatorTest(){ List<Account> accAdd = new List<Account>(); ...
Naveen's user avatar
  • 1
-2 votes
4 answers
134 views

LWC deploy fails without errors

I'm getting a test coverage warning, but not an error. Is the warning the reason why the deploy fails on production? Worked in the sandbox. sf project deploy start -o [email protected] Deploying v59.0 ...
dan-klasson's user avatar
0 votes
2 answers
79 views

Test Code Coverage - Delete DML catch block

We have implemented one method using Apex for delete some records under the class which is without sharing. In the method, first we are retrieving the list of the records(which needs to be deleted) ...
samarpita saha's user avatar
0 votes
0 answers
100 views

PersonAccountId inside a test class

Let's say we've got formula field on Account like this IF (IsPersonAccount , CASESAFEID( PersonContactId ) ,"") Is it possible to create somehow an Account record with a particular ...
pincet's user avatar
  • 927
0 votes
1 answer
42 views

Test class for batch with another class called in it: Batch has 100%, but called class only 24% coverage [duplicate]

Batch class: public class BatchClassForCustomer implements Database.Batchable<sObject>{ public Database.QueryLocator start(Database.BatchableContext bc){ string query='...
Pratik Bokade's user avatar
0 votes
1 answer
43 views

How or do we have anyway to run ValidateMetadata via REST API before creating package version

i'd like to do a check metadata validation in advance even before creating package version in each PR. My question is do we have any way to do check code-coverage verify metadata before creating ...
vctqs1's user avatar
  • 85
0 votes
1 answer
59 views

Help with Test Class for on insert Opportunity trigger [duplicate]

A user can create an Opportunity only by converting a Lead. But for some reason the primary contact on the opportunity is not getting populated. I have created an Opportunity trigger that runs on ...
Sagar's user avatar
  • 1
-1 votes
1 answer
49 views

Code coverage and DMLException - How to enter Exception?

I insert lists that are created from pre-existing data. In my @testSetup I create the mockup but it's 'impossible' to enter the DMLException when trying to achieve 100% code coverage. This is my code +...
Alexis MASSON's user avatar
3 votes
2 answers
229 views

Is There a Best Practice for Associating Apex Test Classes to Apex Classes?

About a year ago, I developed an Apex project that involved a trigger/handler. It included the trigger, a trigger handler class, several helper classes, and a test class. All went well. Recently ...
Ron Van Aken's user avatar
0 votes
1 answer
343 views

Schema.sObjectType.(...).isUpdateable() method is returning true but should return false

In short, I'm trying to follow the PMD Source Code Analyzer Project, and I realized that before making an update I must validate whether the user has permission to change the field (ApexCRUDViolation)....
Noops's user avatar
  • 3
0 votes
1 answer
94 views

Test Class Data for PlatformEventUsageMetric

I have a simple, invocable class to query delivered platform events using the PlatformEventUsageMetric object and it is working in flow, but I'm not sure how to create a test class for it if I can't ...
Kendra Broom's user avatar
3 votes
0 answers
148 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
1 vote
0 answers
103 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
90 views

Test Coverage issue for a simple rest-service class

Just get started with Trailhead but got stuck with one challenge. It requires you to write an apex class to implement a REST GET service to retrieve an account and associated contacts. Then you have ...
user9035826's user avatar
0 votes
1 answer
820 views

System.DmlException: Insert failed. First exception on row 0; first error: INVALID_CROSS_REFERENCE_KEY, Owner ID: owner cannot be blank: [OwnerId]

I wanted to write test class for Triger which insert contact on user Insertion. So I am writing test class to check whether new created contact is related to that user or not but Im receiving error. ...
Sajid's user avatar
  • 13
0 votes
0 answers
90 views

Partial mocking using ApexMocks Framework

I want to perform partial mocking using the Salesforce FFLib ApexMocks framework. For example, I have a class like the one below: public class PropertiesServiceImpl implements IPropertiesService { ...
Seleukos2's user avatar
-1 votes
1 answer
38 views

Help with StandardSetController Test with redirect

I have a visualforce page that grabs the ids from a list view of the selected records. Then redirects to lightning component. I'm having trouble with my test class. I'm not able to get the assertions ...
Jeff Bieber's user avatar
-1 votes
2 answers
206 views

How to do code coverage for Trigger/create a test class and trigger handler for trigger [duplicate]

First, I am totally new to Apex Trigger, I'm still learning the Apex Class and Triggers. I just found a code that actually works in our org. So what it does are below. get the record type id and ...
Paul Grael's user avatar
-3 votes
1 answer
77 views

Apex test class not working and fails

I have the following apex class: public with sharing class TT_DisplayRelatedOpportunities { @AuraEnabled(cacheable=true) public static List<Opportunity> getOppList(String recordId) {...
Marjan's user avatar
  • 15
0 votes
2 answers
65 views

Cannot Increase Code Coverage for Salesforce supplied Lead Conversion Apex Class

I am trying to utilize this Apex Class supplied by Salesforce but when i try to deploy to production i get a code coverage of 68%: global class ConvertLeadAction { @InvocableMethod(label='Convert ...
Zack Gibson's user avatar
0 votes
1 answer
109 views

MIXED_DML_OPERATION, DML operation on setup object

My Apex Class public with sharing class WeekendTimeSheetAlerts implements Database.Batchable<sObject>{ final String weekToSubmit; final String query; final Date weekMondayDate; ...
YETURU CHENCHU's user avatar
0 votes
0 answers
39 views

Need help on my first Test Apex class [duplicate]

I have written an Apex class which works well in dev environment, but I am having a tough time writing a test class that will give me more then 59% coverage. I tried using snippets from this and other ...
Sergio's user avatar
  • 1
-2 votes
1 answer
39 views

I want to cover catch block of this method but unable to as it is related to querying User profile. Please help

I want to cover catch block of getUserProfile method. I am providing the whole code, only catch block of getUserProfile method is not getting covered. TestClass @IsTest private class ...
SF Learner's user avatar
3 votes
1 answer
1k views

How to write an APEX Test Class with Multiple Http Callouts (Renamed)

I'm relatively new to programming, and I am attempting to write the Test Class for an Apex Class that has an HTTP Callout. I have already created the HTTP Mock Class to simulate the Callout, but when ...
nigeldendy's user avatar
0 votes
1 answer
143 views

I want to cover catch block of main class to have 100% code coverage. Can't seem to throw exception. If anyone can help

I am able to cover try block of my main class, but failing to do the same for catch block. Here's the given code for my current test class and Main Class. Controller Class- public with sharing class ...
SF Learner's user avatar
-1 votes
1 answer
24 views

its not covering in my test class can you please anybody help me on this,

obj = SAPIntegrationToGetMAP_SL__c.getInstance('Integration Details'); if(obj !=null){ username = obj.Client_Id__c; password = obj.Client_Secret__c; } for this have written like this @...
sams's user avatar
  • 1
0 votes
1 answer
107 views

Test Class for multiple external objects

I am trying to write a test class for a apex class that contains multiple external objects. I`ve tried the answer in this link. Although test is passed, the code coverage is only 37%. How can I ...
salesforce1234's user avatar
0 votes
1 answer
385 views

How to write test class for generic method to get picklist options

I need to write test class for this method involving the generic method to retrieve Picklist options: @AuraEnabled public static Map<String,String> retrievePicklistOptions(String objApiName, ...
Makc M's user avatar
  • 25
0 votes
0 answers
69 views

schedulable class shows 0% coverage while trying to deploy to Production

I have a Schedulable class which calls a Batch class, I have enough coverage when checking in sandbox, But when trying to deploy to production Scheduler class shows 0% and Batch class shows 60%. I am ...
sangeetha balasubramanian's user avatar
1 vote
1 answer
178 views

Code Coverage requirements for External Services and Flows in Unlocked Packages

I created an unlocked Salesforce package that contains an External Service and an Inactive Autolaunched Flow that calls methods in the External Service. The package does not contain any Apex classes ...
Mary Hamlin's user avatar
0 votes
1 answer
63 views

Will you please tell me how to get test coverage for finish method were sending error mails in this batch class [duplicate]

public class MyBatchable implements Database.Batchable<SObject>, Database.Stateful { Exception[] errors = new Exception[0]; public Iterable<SObject> start(...) { ... } ...
M S's user avatar
  • 3
-5 votes
2 answers
116 views

System.NullPointerException: Attempt to de-reference a null object on test class

I have getting error as System.NullPointerException: Attempt to de-reference a null object on the test class Class:- /* * @Class Description- Contact Trigger Helper. * Class is introduced to handle ...
user68781's user avatar
0 votes
1 answer
69 views

Issue : "No content to map to Object due to end of input" in test classes

I am getting Issue in test class. I am not able to cover the test coverage of responsebody When I debug it show the "common.apex.runtime.impl.ExecutionException: No content to map to Object due ...
Abhi's user avatar
  • 1
0 votes
1 answer
1k views

AssertEquals not working as expected

I have a test class that works on my org dev, I'm trying to make deploy in another org but it's having a strange behavior, the error is in the first assertEqual: @isTest static void testUserStore()...
Alexia's user avatar
  • 83

1
2 3 4 5
27