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
34 views

Test Class Out of Bounds Exception

This is the first time I have messed with test classes, so there may be something I am simply overlooking. However, I am trying to test a simple class but am only getting an out of bounds exception as ...
user avatar
  • 31
0 votes
1 answer
27 views

Run Test Suite from Apex

I have a test suite which contains all test classes. I want to run the test suite from Anonymous Window so at the end of suite run completion I can create custom object records to track the coverage. ...
user avatar
1 vote
0 answers
21 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 ...
user avatar
  • 648
0 votes
0 answers
16 views

test class for attachments for events in salesforce [duplicate]

Hi can anyone please help me with a test class for below two methods global static void insertAttachment(string eventid, Map<String, Object> json_body) { try { Map&...
user avatar
0 votes
0 answers
29 views

Getting full coverage for test class for boolean value? [duplicate]

This UserMigrationRoute class is migrating Community profile users to Partner profile and saving their username Password in userMigration object. I have really hard time writing test classes. I have ...
user avatar
-1 votes
0 answers
24 views

How would I write a test class for this Apex Class [duplicate]

I am new to apex and have managed to hack this together. public class ContactsListController { private String sortOrder = 'LastName'; public List<Contact> getContacts() { String ...
user avatar
-2 votes
0 answers
11 views

How to write test class for this schedulable class? [duplicate]

global with sharing class pokeBatchList implements Schedulable{ global void execute (SchedulableContext SC) { List<Pokemon__c> pokeList = new List<Pokemon__c>(); for(Integer i=1; ...
user avatar
0 votes
1 answer
26 views

Test class for covering running user current application info

I have a class where I am using a method that returns the application label of the current logged in user. I am using that class method in another class method and based on the returned app name, I am ...
user avatar
-4 votes
0 answers
13 views

Want Test class for below class [duplicate]

global class WebAdmitDailyJob implements Schedulable,Database.Batchable,Database.AllowsCallouts { global void execute(SchedulableContext SC) { Database.executeBatch(new WebAdmitDailyJob(),...
user avatar
0 votes
1 answer
34 views

How to write Apex unit test for a function that fetches meta data?

I have a function that returns the list of all custom objects that are currently present in the org, as listed below. @AuraEnabled public static List<String> getCustomObjectNames() { ...
user avatar
-3 votes
0 answers
28 views

I write a test class for my class but didnt get a proper code coverage [duplicate]

public class GenerateCostSheetCtrl { public String recordId {get; set;} public Cost_Sheet__c cs{get; set;} public GenerateCostSheetCtrl(ApexPages.StandardController controller){ ...
user avatar
0 votes
1 answer
17 views

How to get Test Coverage on a Simple Wrapper Class

I'm trying to get a test class to cover a few wrapper classes I've created in Apex, but for some reason one of the wrapper classes doesn't gain coverage (0%) like the other one does (70%). I read in a ...
user avatar
1 vote
1 answer
22 views

Test Method Issue for removing duplicates from List

I have a requirement to remove the duplicate objects from a list at several places in my integration code and I have developed a method in the Util class to remove the duplicate objects from the list. ...
user avatar
0 votes
0 answers
37 views

How to get 100% test coverage for an apex trigger associated with an asynchronous callout?

I am looking for assistance on why 'zipCodeTimeZone.makeCallout(objLead.Id)' in both places on the trigger is not being covered/triggered by my test method while it is providing 100% coverage for the ...
user avatar
  • 1
0 votes
0 answers
19 views

Code Coverage On FinServ Batch Job

I am new to Apex and am having a lot of trouble getting the code coverage to 75% on the bellow Apex Class. I had previously posted on the dev forum for salesforce and got coverage up to 71% by just ...
user avatar
0 votes
0 answers
46 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
24 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
23 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
25 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
62 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
51 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
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
32 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
38 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
105 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
43 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
74 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
83 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
  • 255
0 votes
1 answer
60 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
  • 47
0 votes
1 answer
55 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
49 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
101 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
472 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
68 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
48 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
26 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
  • 255
0 votes
1 answer
272 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
61 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
60 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
70 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

1
2 3 4 5
25