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
3answers
24 views

Querying Apex Classes & Dependent Test Classes

Does anyone have any advice on how I can go about querying test classes and dependent test classes? Our Org is getting very large and finding the correct test classes for each class is becoming an ...
-1
votes
0answers
13 views

How to do code coverage of custom labels in salesforce? [on hold]

I have used custom labels in a class and for that class I want code coverage more than 78% but because there are custom labels presented, not able to cover it. So help me out in this situation.
-1
votes
1answer
26 views

Code coverage for delete statement in batch class [duplicate]

How can I get increased coverage for this code? I get only 75% so far. Not able to cover the delete statement in the main class. Any help is greatly appreciated. Main Class: public void execute(...
-1
votes
1answer
35 views

Test method with not writable fields

Please help me test the method because I'm at a dead end. It does not return anything, but sets values ​​to two custom fields subject to several conditions. Half of the method is covered by tests, ...
0
votes
0answers
25 views

Test Class for Page Reference Method Help [duplicate]

I'm not sure where to get started with writing this test class. I'm a junior developer and when trying to test createCourse PageReference method I get either an insert or assert fails, or I get an ...
-2
votes
2answers
28 views

Help to cover the test class of given trigger i have got 70 % code coverage but else part is not covering [closed]

trigger TriggerPickListUpdate on Lead (before update) { List<lead> leadList = new List<lead>(); List<String> pickListValuesList = new List<String>(); for (Lead ld: ...
0
votes
3answers
35 views

Test cases in a list

I am trying to get code coverage for my list/loop but no matter what I try I am missing something and could use a hand if possible as I am trying to learn more about Apex. Trigger: trigger ...
1
vote
1answer
41 views

Everything worked fine in Production - but not enough code coverage in Salesforce

I've been tasked with updating our Salesforce. I'm a pretty experienced Salesforce Admin but I have to admit I know very little about apex code. Here's the situation. I've tested everything in ...
0
votes
2answers
28 views

Test Class for SOQL query failing

I have a apex class that is a SOQL query on a custom object. The query works just fine, however, when trying to deploy to production, deployment fails because it seems apex class has zero % code ...
0
votes
0answers
29 views

Attempting to get better code coverage on fairly simple trigger [duplicate]

I am new to working with Map objects in Apex and it has introduced a wrinkle to my test class process. I am only able to achieve 74% coverage and I absolutely cannot figure out why. This trigger is ...
-3
votes
0answers
14 views

I am not getting the code coverage for the trigger.where am i missing.Can somebody help me out [duplicate]

trigger BusinessUnitFieldAutoUpdate on Opportunity (before update,before insert) { Set<Id> accid=new Set<Id>(); Set<Id> accownerid=new Set<Id>(); for(Opportunity tl:Trigger....
-3
votes
0answers
27 views

Code Coverage Salesforce

Hi i get the following Error on deploying a new changeset in Salesforce. But have no idea why. Code Coverage Failure Your organization's code coverage is 73%. You need at least 75% coverage to ...
0
votes
1answer
29 views

Error While updating the Owner of the Case to queue Id

Hi I am having the scenario where i need to update the owner of the case to a particular queue. but i am getting the error as below : System.DmlException: Update failed. First exception on row 0 ...
0
votes
1answer
23 views

Question Concerning making a Test class for a before update trigger that sends an email

I'm currently trying to make a test for an apex trigger that sends an email if a certain donation field has been changed(before this I tried using a workflow but for some reason it did not work). From ...
0
votes
2answers
47 views

mock test class and test class for 2 classes

I have 2 class A and B. A has code for Http Callout and from B we are calling A's class method which has callout code. So should we write mock test class for A only or do we have to write mock test ...
0
votes
1answer
23 views

Get ApexCodeCoverageAggregate resultes in CSV

I am using the belwo querying in Query Editor in Developer Console: SELECT ApexClassOrTrigger.Name, NumLinesCovered, NumLinesUncovered FROM ApexCodeCoverageAggregate Enabling the Tooling API like ...
0
votes
0answers
14 views

Apex Code Coverage for if/else if test class [duplicate]

if (userList.size() > 0 ) { String profileName = userList[0].Profile.Name; if (profileName == 'CP_CorporateAdminUser' || profileName == CP_SystemConstants.CORPORATE_OPERATION) { ...
0
votes
2answers
26 views

Test Method Fail on Apex class with Meta Object

I am writing a simple api callout for Tsheets, and its working just fine, now when writing the test class, its failing on the line "object results = Meta.get('results')". The error is: System....
0
votes
0answers
15 views

How to write the Test class for the Apex Trigger [duplicate]

trigger populateContactEmail on Case (before insert , before update){ Set<Id> setConIds = new Set<Id>(); for(Case obj : trigger.new){ if(obj.Secondary_Contact__c != null) ...
0
votes
1answer
31 views

My test class code coverage is 100 percent but it is giving following error in run

For report event my test class code coverage is 100% but it is giving following error System.UnexpectedException: common.exception.SfdcSqlException: We encountered an unexpected error. Contact ...
0
votes
1answer
27 views

Test class not working for more than two or three methods in same class it fails for other two methods only one method covers

public with sharing class TransactionsalSecurity { @AuraEnabled public static List<ReportEvent> TransactionalSecurityToday() { return [SELECT Name, QueriedEntities, Format, ...
0
votes
0answers
23 views

Need Help for Apex Test Class [duplicate]

i have a problem with test code coverage of my trigger: that's the code: public class OpportunityLineItemTriggerHandler{ public static Boolean isTriggerFire = true; public static void sync(Set<Id&...
0
votes
0answers
17 views

Trigger.newMap and Trigger.oldMap not able to pass the correct values in the test Class! [duplicate]

I have a scenario to cover in the Test Class Whenever Case is assign to queue from User : particular field must get blank: public static void wmgRemoveOldGroupQueue(Map<Id,Case> newMap, Map&...
-2
votes
1answer
19 views

Error: No more than one executeBatch can be called from within a test method [duplicate]

Test Class: @isTest private class UsersFreeze_batch_Test{ static final String COMP = 'HID Global'; static final list<Countries__c> COUNTRIES = new list<Countries__c>([...
0
votes
0answers
29 views

How to validate Old and New Values of ContactHistory in Test Class

I have an apex class which looks for the old and new values of contacthistory. I am writing a test class for this, but could not write data to Oldvalue and Newvalue. I also tried updating the field ...
0
votes
0answers
14 views

Test Class Failing for a Batch Apex Class [duplicate]

I have created a test class which tests the code for a batch apex class but the code coverage is only 62%. I'm really stuck and don't know how to get over it. I'm new to salesforce and any help would ...
0
votes
0answers
14 views

Test Class Code coverage Improvement

My test class @testSetup static void createTestRecords() { User thisUser = [ select Id from User where Id = :UserInfo.getUserId() ]; System.runAs( thisUser) { //creating User ...
0
votes
1answer
21 views

REST Endpoint Returns NULL in Test Class

I have a RestResource mapped to /Demo/ that I place on a Salesforce Site. The rest resource works great, including the parameters. However, in my test class I cannot get it to return anything to ...
-3
votes
1answer
64 views

Not able to get the expected Assert statement in my test Class

My Assert Statement is failing in the below logic and i am not able to get the proper expected value , Please find the Codes in the Screenshots. Logic: public static void wmgRemoveOldGroupQueue(...
1
vote
0answers
69 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
14 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
97 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
57 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
133 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
28 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
47 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
151 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
66 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
0answers
33 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
37 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 ...
2
votes
1answer
33 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
31 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
58 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
12 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&...
2
votes
1answer
47 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
26 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
32 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
17 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 ...