Last call to make your voice heard! Our 2022 Developer Survey closes in less than a week. Take survey.

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
0 answers
26 views

System.DmlException: Insert failed. First exception on row 0; first error: FIELD_INTEGRITY_EXCEPTION, role type must match user type: []

I Am getting this error System.DmlException: Insert failed. First exception on row 0; first error: FIELD_INTEGRITY_EXCEPTION, role type must match user type: [] Stack Trace: Class.TestDataFactory....
user avatar
  • 1
0 votes
1 answer
20 views

Test class for a check if null method

I've been trying to write a test class for a method that checks if an object is null. @RestResource(urlMapping='/register-sequence') global class RestClassToTest { @HttpPost global static void ...
user avatar
0 votes
0 answers
20 views

Unable to Run Batch Test Classes. Please help me [duplicate]

I have written Batch Class which is working fine (batch class is written below), now I want to write its test class. The one I have written is not giving 100% code coverage (only 30% is covering), it'...
user avatar
1 vote
1 answer
20 views

Uncovered lines not shown in sfdx deploy (check only) command anymore

Our CI/CD pipeline has not been changed in past 4 months, But i clearly remember in case of code coverage issue. Uncovered lines used to popup. Was there any change in sfdx command where we need to ...
user avatar
2 votes
1 answer
26 views

How to use Cobertura and JUnit reporters with LWC Jest?

When creating a new SFDX project, the default Jest configuration for LWC unit tests looks like this: jest.config.js const { jestConfig } = require('@salesforce/sfdx-lwc-jest/config'); module.exports =...
user avatar
0 votes
1 answer
20 views

Test Code Coverage for Querying

I'm having some problems trying to write a test class. The issue is, the class which is being tested is composed of 5 methods that receive some information and use that information for querying. They'...
user avatar
0 votes
0 answers
32 views

COVER IF CONDITIONS [duplicate]

I have an apex class and a Test class already created. Now have added few IF CONDITIONS in my apex class, but I am unable to cover those in my TEST CLASS. APEX CLASS: global with sharing class ...
user avatar
0 votes
0 answers
31 views

System.runAs() does not function as expected

static testMethod void testForDeletePrevent(){ PCA_Settings__c pcaConfig = TestDataFactory.createPcaSettings(); Common_Settings__c config = TestDataFactory.createCommonSettings(); ...
user avatar
0 votes
1 answer
38 views

How to cover catch block in apex test?

Can you please tell me how I can cover the Catch block? public static Map<Id, User> getUsersMapByProfileId(Set<Id> profileIds) { try { return new Map<Id, User>([SELECT Id ...
user avatar
-1 votes
0 answers
69 views

Controller Extension Unit Test: 90% assistance reaching 100% [duplicate]

(WorkOrderController.apxc) - Visualforce Page Extension public class WorkOrderController { work_order__c request; public Id formId {get;set;} public string fileData {get; set;} public ...
user avatar
0 votes
0 answers
9 views

Need to Create Test Class for Apex Trigger that Prevents File Deletion if Attached to Opportunity [duplicate]

Need to get Code Coverage up, and not sure how to write a test class for this. Code below. Thanks for your help! trigger PreventOppyFileDeletePROD on ContentDocument(before delete) { if (Trigger....
user avatar
0 votes
0 answers
29 views

UNIT TEST TRIGGER - Coverage Test Trigger and using System.assertEquals [duplicate]

Hello, I'm new to salesforce and I have a problem with test coverage and System.assertEquals My coverage is insufficient And I get this as an error: Errors : System.AssertException: Assertion ...
user avatar
-3 votes
1 answer
34 views

Code coverage not getting increased, getting "Attempt to de-reference a null object" [closed]

My code coverage is not getting increased. I'm getting "Attempt to de-reference a null object" error. Kindly help me in fixing errors! Constructor: public SampleDeliveryController() { ...
user avatar
-1 votes
3 answers
81 views

How to write a test class for this below code can anyone help me [duplicate]

I want to write a test class to achieve 100 % code coverage for this below code can anyone help me to solve this problem i don't know how to write a test class for using this trigger Trigger: trigger ...
user avatar
0 votes
0 answers
11 views

Trying to get a higher coverage [duplicate]

I'm trying to get at least 75% code coverage at the moment I'm getting 53% (14/26). I was wondering what I need to do to get 75% or higher. Otherwise, my method is passing the test. public class ...
user avatar
0 votes
0 answers
26 views

I am badly stuck in Test Class unable to get coverage more than 56%. Please help me [duplicate]

Test Class ClmSuiteCountrySettings__c testcs = new ClmSuiteCountrySettings__c(Name = UserInfo.getDefaultCurrency(), IsSampleLimitEnabled__c = true,IsSampleModuleEnabled__c=true); insert testcs; ...
user avatar
0 votes
0 answers
13 views

How to write a test class for Signature Attachment on a record in Salesforce? [duplicate]

I have a community page where a user submits their information in a form of Referral (object in Salesforce) and before they hit submit, they are asked to provide a digital consent. The signed image is ...
user avatar
0 votes
0 answers
15 views

How to write test for this controller [duplicate]

I'm new with Apex and controller. I have Apex controller that I don't know how to write test for. It's very simple controller. I have 2 object: Asset_Name__c, Cash_Outlay__c. The Cash_Outlay__c object ...
user avatar
-1 votes
1 answer
36 views

Code coverage at for loop does not cover code inside loop

Why is my apex test not getting the material inside the for loop? I have test data, and the method gets called. I just don't have coverage for anything inside the for loops as seen below. I included ...
user avatar
  • 29
1 vote
0 answers
53 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'...
user avatar
0 votes
1 answer
43 views

How do I write test class for an OpportunityContactRole that has a loockup field for contacts?

the situation is as follows, I have the opportunity, and inside it I have the Contact Roles and inside the contacts roles I have a lookup field that points out contacts, my test coverage is at 97% but,...
user avatar
  • 1
0 votes
1 answer
36 views

Test class for an Apex class with ContentDocumentLink [duplicate]

I have written a LWC component for file upload using ContentDocumentLink and it is completed. Right now I am writing a test class for the Apex class. Apex class: public with sharing class Sitevisit{ ...
user avatar
  • 43
0 votes
1 answer
54 views

How to test Apex queueable is stopped with given condition?

Here is my queueable, which stops at the beginning when condition is set. It seems that the initiated queueable instance in Test is gone after Test.stopTest()? The test execution error is Expected: ...
user avatar
  • 843
0 votes
0 answers
44 views

How to test a function that does a callout from another function?

In the code below, I'm calling GetBusinessDetails, which does a callout, from another function. The problem is, the lines with the asterisks are not getting hit when I run a test and that lowers the ...
user avatar
  • 15
0 votes
1 answer
68 views

Code Coverage for "Auth.SessionManagement.getCurrentSession()" fails

In my test classes, when I come across a line which captures the current user's current session it fails with the following message “Unexpected Exception: Current session unavailable.". Is there ...
user avatar
1 vote
2 answers
289 views

Executing a static method from another class and adding parameters

I need to fix some Apex test coverage and I have the the following issue: I have my controller class like this: public with sharing class someClass{ public Boolean isTestClass = false @...
user avatar
0 votes
1 answer
50 views

Apex Limits.getQueueableJobs() in test class

I have a class where there is a if condition as below if (Limits.getQueueableJobs() == Limits.getLimitQueueableJobs()) In real time its called from batch context and Limits.getLimitQueueableJobs() is ...
user avatar
  • 9
-3 votes
1 answer
26 views

I am not getting full code coverage in my test class, is it because test data isn't setup correctly?

I'm new to Apex and have been working on a class as a training excersize. The invocable method works as expected when called from a flow but I'm having trouble getting the proper code coverage. I ...
user avatar
  • 31
-3 votes
1 answer
47 views

Need Code Coverage for Wrapper class [duplicate]

I have a wrapper class. I am trying to cover the code coverage. Apex Class: public class AccountRelatedListController { @AuraEnabled(cacheable=true) public static list<DataTableWrapper> ...
user avatar
0 votes
0 answers
14 views

How do I create a test class to validate my invocable method class that creates a task through a flow? [duplicate]

I'm really struggling with writing my first test class for an Invocable method. The Invocable method will be fired from a flow. Here is the class: public class DynamicEmailActivityLog { @...
user avatar
0 votes
1 answer
25 views

Test Class code coverage ( only couple of lines )

Hello this is the first time i try to write a test class, but i don't understand exactly how i can test if the flow was actually launched. Can someone help me with the test class ? It's only a couple ...
user avatar
-1 votes
1 answer
27 views

General test of the org?

Is there a way to do an organization-wide test? My internship supervisor told me the following: "What I'm going to ask you to do is run a general test of the ORG and see what the percentage of ...
user avatar
  • 1
0 votes
1 answer
163 views

Test class for before update and before delete trigger

I am new to Salesforce and need to write an Apex test class for this Trigger. I tried this code, but it seems not correct. @isTest public class FormBeforeDeleteTest { public static testmethod ...
user avatar
0 votes
1 answer
47 views

How can I send a really large string value to a method?

I have the following method that I am trying to test global static void updateLoggerError(String msg){ try { Logger.error(msg); }catch (Exception ex) { System....
user avatar
  • 15
0 votes
1 answer
56 views

Test Class for updating count on another Object using Aggregate

The code is working fine and covering only 54%. My test Class could not covering AggregateResult (Bold Part) trigger DrawingSharing on Drawing__c (after insert, after update) { if(trigger....
user avatar
  • 1
0 votes
1 answer
56 views

Test Class is not covering the part where I extract Case Id from custom object Long Text Area and split the string

I have created a trigger with handler that stamps the Case Id on custom object Case__c field. The trigger and class works fine. But my test class is not covering the part where I split the custom ...
user avatar
0 votes
1 answer
50 views

My test class doesn't have enough coverage. How can I fix it? [duplicate]

@isTest public class TSNotesToReferralBatchTest { public static List<Account> testDealersList = new List<Account>(); public static List<TS_Consultant_Note__c> noteUpdateList =...
user avatar
0 votes
4 answers
72 views

httpCallout @future

can please someone tell me what I am doing wrong. I am only able to get 30 percent test converge. I am unable to get test converge for the http. Any suggestion is much appreciated Thank you! public ...
user avatar
  • 11
0 votes
1 answer
86 views

covering test class if condition for a variable defined in method

public static String myMethod(String vehicle1){ string abc = 'car'; if (abc == 'bike'){ // lines of code } } Here the issue that I am facing is that the lines of code inside the ...
user avatar
4 votes
1 answer
342 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 --...
user avatar
0 votes
1 answer
77 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....
user avatar
  • 5
0 votes
2 answers
65 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, ...
user avatar
0 votes
0 answers
30 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 ...
user avatar
0 votes
1 answer
41 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 ...
user avatar
  • 197
0 votes
1 answer
98 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 ...
user avatar
-4 votes
1 answer
54 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&...
user avatar
-4 votes
1 answer
47 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;...
user avatar
0 votes
2 answers
40 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 ...
user avatar
  • 750
0 votes
1 answer
29 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....
user avatar
0 votes
1 answer
36 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, ...
user avatar

1
2 3 4 5
25