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.

113 questions with no upvoted or accepted answers
Filter by
Sorted by
Tagged with
4
votes
0answers
73 views

Perform a deployment and execute all tests with a flag to opt out of collecting code coverage

I'd like to perform a deployment and execute all tests with a flag to opt out of collecting code coverage. The goal is to speed up Apex test execution. I'm aware that we can do it manually by ...
3
votes
0answers
65 views

Salesforce Connect Custom Adapter test class

What is the correct way to approach testing Salesforce Connect custom adapters? Perhaps there is a unified approach to testing all of its parts, but specifically what is the approach for testing the ...
3
votes
1answer
192 views

Test Class: Unable to assert enqueueJob

The queueable job is enqueued in the finish method of the batch class but I am unable to assert in the test that queueable job got enqueued. System.enqueueJob was returning null Id in the test then I ...
3
votes
1answer
187 views

sosl exception on searching with one character

On doing a sosl search with just one character search parameter, I am getting an exception. To overcome this i have used custom error message in the catch block.However I am unable to cover the catch ...
3
votes
2answers
577 views

85% code coverage yet upload fails

Hi I have 85% code coverage as stated by the developer console. All my classes have a test class and are above 75% with the only exception being my trigger at 66% coverage. The error is as follows: ...
2
votes
0answers
885 views

Test class for community to get network id

i am facing problem with getting network id in test class, while executing visual force page, controller returns proper network id, when try to write a test class for this 'ClassNetwork' controller, ...
2
votes
0answers
293 views

OrderItem does not have ListPrice set in test, contrary to non-test

This is something I've run into and worked around, but it still annoys me because I have to write test specific things in my non-test code (and can't get to 100% coverage because of it). I can find ...
2
votes
0answers
1k views

How to succesfully test AgentWork trigger?

I am using AgentWork trigger in my logic and I cannot achieve code coverage goal. Simple test method: Id cId = [SELECT Id From Case Where Subject = 'Case Subject'].Id; User u = [SELECT Id From User ...
2
votes
0answers
153 views

Code coverage is 70% and I get a DUPLICATE_VALUE issue

Code coverage is 70% and when I dive into the problems I get a duplicate error. Please help I am new to writing triggers. Thank you ahead of time! Problem on several Lines Message: [object ...
2
votes
0answers
179 views

Data displaying in Overall Code Coverage section in developer console is not consistent

The data displaying in Overall Code Coverage section in developer console is not consistent, but displays incorrect code coverage sometimes 100% and sometimes with lesser number. For example, ...
2
votes
0answers
655 views

How to write test class for Default Account Team Members?

I am writing a test class which needs to cover code related to default account Team members. UserAccountTeamMember doesnt allow DML operation. Can you please let me know how to solve this issue in ...
1
vote
1answer
22 views

Do Apex tests (have to) run as part of the deployment when we deploy Processes and autolaunched Flows?

When you have enabled the setting 'deploy processes and flows as active' you need 75% of Processes and Autolaunched flows to have at least some Apex code coverage. The documentation on Running Apex ...
1
vote
0answers
16 views

Apex test class for covering site.login and it's exceptions

I'm currently having an issue in covering site.login and its exceptions in our test method. The exceptions are handled to cover the failed logins in our portal. This exception thrown from apex is ...
1
vote
1answer
42 views

DmlException: Merge failed. First exception on row 0 with id first error: DELETE_FAILED

Error: System.DmlException: Merge failed. First exception on row 0 with id first error: DELETE_FAILED,TargetX_SRMb.ContactTrigger: execution of AfterDelete caused by: System.NullPointerException: ...
1
vote
0answers
109 views

Apex MyProfilePageController class bug

While trying to deploy apex changes to prod I receive an error for the MyProfilePageController class. I found https://developer.salesforce.com/forums/?id=906F000000099W9IAI. This is an issue from 2010,...
1
vote
1answer
204 views

Validation Errors While Saving Record(s) while executing test class

I am trying to execute a test class and getting this error : "Validation Errors While Saving Record(s)" There's no explanatory text or anything else which can help me to resolve this issue. We have ...
1
vote
0answers
189 views

Code Coverage 95% in sandbox and 47% in production for a class

I am at a loss right now why my code coverage is off for a particular class. I have @isTest(seeAllData = false) in my test class and I am creating my own data. I have also cloned a new sandbox from ...
1
vote
0answers
182 views

Apex test classes fail on HTTPResponse

I have some test classes that run decently until they hit something like HTTResponse res = h.send(req); Where I then get 'System.UnexpectedException: Script-thrown exception'. I make a few ...
1
vote
0answers
82 views

Testing @RemoteAction method with mock data inserted in factory

I'm struggling a little bit with accessing data which has been inserted through factory method in my RemoteAction method. Here is a code of RemoteAction method : @RemoteAction global static ...
1
vote
0answers
85 views

Apex ContentDistribution in testmethod

For covering an apex class I need to create ContentVersion + ContentDocumentLink + ContentDistribution I succeeded in creating the first 2 but failed with the ContentDistribution (Internal Salesforce ...
1
vote
1answer
255 views

Test Class coverage for UserAccountTeamMember

I have a test class block which I am unable to cover as it queries UserAccountTeamMember object for a default account team member. I tried to insert record in that object through test class but DML is ...
1
vote
1answer
193 views

How to write a test class for covering Bundle product?

I am trying to cover a class in which I have below condition which contains one variable called SBQQ__Bundle__c available on QuoteLine Object of steel brick CPQ. I have tried to investigate regarding ...
1
vote
2answers
101 views

when user deactivate assign case to queue in test class

public class Helper { @future public static void dummyUsers(Set<Id> userIds) { }
1
vote
0answers
144 views

A lower code coverage problem when trying to deploy

All my apex classes have more than 90% code coverage. But, when I am trying to deploy them, it is showing I have 59% code coverage. How to solve this issue. I have run all test, & check all apex ...
1
vote
1answer
208 views

Wrote a trigger to prevent record deletion, now need help with test class

I'm a newbie when it comes to writing triggers and test classes. I've written a trigger that prevents the deletion of a record on a custom object, System_Integration__c, when a date field (...
1
vote
0answers
22 views

Enforce DML statement to be failed within a batch

I am trying to make a DML statement in a batch to be failed. The reason for this is that I have logic executed in my batch in case the DML failed for some records. I would like to test it and get the ...
1
vote
0answers
171 views

Test Class with @invocableMethod

I wrote an Apex Class (with the help of some code I found on the internet, because i'm not a developer) to help automatically post some content to chatter with @mention. This Class had a @...
1
vote
1answer
52 views

Test Code for Conditional Event Deletion is not running expected lines

I'm having some problems with a test class and I honestly can't figure out why. Maybe I've been staring at it for too long, but in any case - would appreciate if someone can tell me where I've gone ...
1
vote
0answers
99 views

How to write test cases for Salesforce application to check its code coverage with an example of making a test case for a code example?

I want to write test classes for my apex code to get code coverage. I have seen this documentation to get idea about test classes but I am not clear about test classes w.r.t my apex classes. So, I am ...
1
vote
1answer
107 views

how to identify correct code coverage in SalesForce?

I am getting issue with code coverage percentage. In my dev org it is showing 84% but when I am trying to create package then it is showing 74% and I am not able to create package. I have cleaned up ...
1
vote
0answers
281 views

Incorrect code coverage in developer console

I have an apex class called RelationshipTreeController (RTC for short) and a test class called RelationshipTreeControllerTest (RTCT for short). I have written a test method that calls the search() ...
1
vote
0answers
1k views

Assistance with a Test Class to increase code coverage

This is a follow up to my previous question of Is there anyway to deactivate a trigger in Prod when the minumum code coverage is not met. I am not an apex developer and I am the only SFDC Admin at my ...
1
vote
0answers
189 views

Issue: Salesforce UI, Developer Console and Eclipse IDE shows different code coverage for the same class. Is anyone experienced this?

This is very much confusing and hard to believe which one is valid. Below screen shot describes the issue as the code coverage for one of the class "OpenDocumentsController" showing 100% (179/179) in ...
1
vote
0answers
176 views

why test coverage includes all classes and triggers when creating an unmanaged package with selected classes?

Trying to create an unmanaged package with few classes but i am getting the following error when i try to "Upload". There are other Apex classes and triggers in my free dev org for which i do not want ...
1
vote
0answers
302 views

See the code coverage of my package without uploading it

I have a packaging org of a managed package and only 60% of its classes are actually part of my managed package. How or where can I check the code coverage of only those packaged classes without ...
0
votes
1answer
20 views

Unmanaged package error

I have created a lightning component and want to create a package for that i wrote a test class for apex class coverage too which is showing 100% code coverage but when iam trying to upload the aura ...
0
votes
1answer
15 views

How to cover piece of code using test class which is checking if its sandbox or Production

I have below Peice of code which is chekcing if its sandbox then run If part else run Else part if(runningInASandbox()) { return getSsoRedirect('one', startUrl, ...
0
votes
0answers
27 views

force:mdapi:deploy fails with RunLocalTests + test coverage > 75%

As other people (see Code Coverage during sfdx force:mdapi:deploy) I am unable to move code using sfdx force:mdapi:deploy to another org due to Apex Class Coverage. But as @sfdcfox notes out: If ...
0
votes
0answers
25 views

Httpresponse is not getting coverd in testclass

My response was stored in static resource and I am setting fake response by staticresource method to class but my Httpresponce is not getting covered in test. @isTest global class SmartSheetUtil_Test ...
0
votes
1answer
44 views

Code Coverage 83% in production 75% in sandbox - can't deploy

In production, code coverage is showing 83%. In sandbox, it is showing 75%. I have just 1 apex class and associated test class I am trying to deploy to production, but it fails saying only 30% ...
0
votes
0answers
27 views

Getting error while running test class-System.NoAccessException: Set up My Domain to access this page

i am into the situation where from Developer console my test class is getting passed but from UI -its with error 'System.NoAccessException: Set up My Domain to access this page.' Please suggest. ...
0
votes
0answers
155 views

test class coverage for process instance

Hi I am submitting record for approval in test class, and then again I am approving it. Still the status is showing as pending. Can anyone help here? public static testMethod void ContractTestMethod()...
0
votes
0answers
69 views

Code Coverage - Salesforce Connect Custom Adapter / Datasource.Connection Class

I am unable to find documentation on or get any code coverage for the customer adapter Apex Class (Datasource.Connection Class). For awareness, the external data source and customer adapter functions ...
0
votes
1answer
44 views

Custom Controller Test Coverage

Having a bit of difficulty getting any code coverage for my custom controller. The goal of the controller is to display a list of opportunities in a list where the division of the user is the same as ...
0
votes
1answer
200 views

Test class for method with API call and return type String

How do we write test method for Apex class used by Lightning component where my return type of method is String but within the method I call rest api Here is my class method: public static String ...
0
votes
0answers
228 views

Not covering batch execute method querying CampaignMember

AccountActivityUpdateBatch class execute method is not covering the for loop. Here is my test class. @istest public class AccountActivityUpdateBatchTest { @testSetup static void setup() { ...
0
votes
1answer
54 views

Apex Trigger Code Coverage Deployment Validation Inconsistent with Debug Logs

I have a test class for a trigger on a new custom object (Sample) that covers nearly 50% of the trigger in Sandbox, and is nearly identical to another trigger for a different (older) custom object (...
0
votes
1answer
83 views

Test batch class - object WorkOrder

I'm building a batch class to update the WorkOrder. But I can't call the method execute to test this part. How can I test my logic inside the try in the execute method in batch classes? global class ...
0
votes
1answer
15 views

Issue in test class code coverage to increase code coverage

I have one class and to cover test class i have written one HttpCalloutMock class global HttpResponse res(HttpRequest req) { HttpResponse res = new HttpResponse(); res.setHeader('Content-...
0
votes
1answer
181 views

Failed to assign topic to null. Please ensure you have permissions to assign topics for this record.: [EntityId]

Iam getting below error after running test class: System.DmlException: Insert failed. First exception on row 0; first error: INVALID_FIELD , Failed to assign topic to null. Please ensure you have ...