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
-3
votes
1answer
37 views

Unable to cover code in test class [duplicate]

I have created a test class for one of my client's class. Below lines are not covering even though I created a test record for that. Class: public without sharing class ContractLogCreationController { ...
-2
votes
0answers
31 views

How to cover Wrapper class in test class

I have created a Test class for below class, but my method is not covering. I have tried to figure it out but no luck. Class: public without sharing class ContractLogCreationController { @...
0
votes
1answer
21 views

System.QueryException: List has no rows for assignment to SObject. How to resolve it [duplicate]

I have created a Test Class for below class. I am getting "System.QueryException: List has no rows for assignment to SObject" error. I have tried a lot but no luck. Class: public class ...
1
vote
0answers
23 views

Test Class on an Update Trigger

This is my very first trigger. It does exactly what I intended it to do. trigger FirmAssociationTrigger on Opportunity (before update) { for(Opportunity a : Trigger.new) { // Get the ...
0
votes
2answers
48 views

Test run for Web Service Callout batch class

I have an apex class which fetches and upserts data from external source to Salesforce. Below is the batch class: global class PolicyCalloutBatchClass implements Database.Batchable<Integer>,...
-2
votes
0answers
51 views

Apex Test Class Failing - Fields Not writeable [closed]

Here is my Apex Class: public with Sharing class abcService{ @AuraEnabled public static List<customObject> xyzMethod(){ UserAppInfo userAppInfo = [SELECT Id, AppDefinitionId FROM ...
0
votes
1answer
44 views

Test Class Coverage for Apex Controller [duplicate]

I need help in writing test class for following apex class. Could anyone please suggest how to create test data,test the following method defined in apex class with positive and negative scenarios and ...
-1
votes
0answers
27 views

How to write a test class for a method which returns Boolean if a milestone of a case is expired? [duplicate]

Public static bolean checkmilestone(Id currentcaseId) { Bolean isexpired=true; CaseMilestone milestonedata=[select id,isVoilated,Lastmodifieddate from caseMilestone where caseid=currentcaseId orderby ...
0
votes
1answer
14 views

Calling component controller through VF page by passing id as parameter

I have to write a test class for a controller . It is a component's controller. The component is called in a VF page in below fashion <apex:page standardController="Obj1__c" extensions=...
0
votes
1answer
32 views

Class having 100% code coverage on UAT can't be deployed due to 63% during production deployment text check

I have apex class SalesProcess which has 100% code coverage in UAT. But during deployment to Production I get error saying that it is only 63 % covered. No other error just that. The class: public ...
0
votes
0answers
26 views

Creating a test class for a trigger help! [duplicate]

I am new to Salesforce and I am struggling to write a simple test class. I haven't written one before though I have been doing a lot of trailhead on it but can't seem to wrap my head around this test ...
0
votes
1answer
44 views

Test class error: System.CalloutException: You have uncommitted work pending. Please commit or rollback before calling out [duplicate]

I could have sworn this was working 2 months ago and now it seems suddenly broken (there are some slight changes I have tried to make today - making the method calls @future in @testsetup, also adding ...
0
votes
1answer
22 views

My SFDX Project in VS Code doesn't pickup any test classes

Even though I have test classes and test methods in my SFDX project in VS Code none of the test methods gets picked up in the test panel. I have configured a JDK in my VSCode here and enabled What ...
0
votes
0answers
11 views

Apex Test Class for PageReference urlRedirection() [duplicate]

I'm hoping someone may be able to help with a very rudimentary test class. I'm brand new at coding apex and I have a very simple redirecting VF page with a very simple controller that I need to ...
0
votes
1answer
29 views

ApexOrgWideCoverage history

The below tooling API returns the org wide coverage, it is working fine . do we know how to get teh history of the coverage. say how is teh coverage in the last week and to see over the period? SELECT+...
0
votes
0answers
42 views

Test class where a single method calls two Webservices in a row [duplicate]

I need to create a Test class where a single method (doPost()) calls two Webservices in a row. The first is a REST API and the second is a SOAP API. The first API retrieve a token that I need to use ...
-1
votes
1answer
18 views

how to cover this catch in my batch?

for (APC_I_c rAPC : scope) { rAPC.Error__c = null; rAPC.Type_of_Error__c = null; rAPC.Status__c = 'Processed'; if(rAPC.APC_ID_Account_RCS__c != null){ ...
0
votes
1answer
24 views

Test Coverage discrepancies for QuickAction.QuickActionDefaultsHandler

Test Class runs successfully and test coverage is 100% but fails during deployment saying "Your Code Coverage is 70%". @isTest public class DefaultSignatureForEmail_Test { static { ...
0
votes
0answers
51 views

INSUFFICIENT_ACCESS_ON_CROSS_REFERENCE_ENTITY : [NetworkId]

I've written a simple trigger to enforce our Community users not to delete files. Currently, I'm facing an issue in getting test coverage for deployment. Trigger trigger ContentDocumentTrigger on ...
0
votes
2answers
29 views

Test Coverage For EmailMessage Trigger [duplicate]

I wrote some code to update the Initial Response field on a case when an outbound email is sent. I can't seem to get enough coverage to deploy the trigger handler. Here's my code Trigger trigger ...
1
vote
0answers
56 views

System.SObjectException: Field is not writeable: [duplicate]

We have the following code and Apex Test Class, and for some reason during Apex Test Execution (Developer Console-->Run Test) it is throwing the following error message below. Any ideas why the ...
1
vote
1answer
24 views

Testing a class that has multiple callouts?

What is the best practice for writing apex test classes where you have multiple callouts? My Test Class would then be testing the secondCallout method which happens to also call a firstCallout method ...
0
votes
1answer
25 views

Writing Test Code for Boolean Result

I have been through Trailhead and read multiple references, but am still not getting passing tests. I'm sure I'm missing something simple and need assistance with writing a passing test for a method ...
0
votes
1answer
22 views

Refactoring Help for main class or test code coverage

I'm trying to refactor the following code.I'm trying to figure out how to refactor this code OR if anyone have a good way to do code coverage for this. My issue is that, in dev, the code coverage is ...
0
votes
1answer
19 views

Cant reach the full code coverage while testing trigger

I think,the problem may be in account and contact connection here is my trigger code: List <Contact> contacts=Trigger.New; for(Contact c: contacts){ Case cs=new Case(); ...
0
votes
2answers
62 views

ContentDocument ID: id value of incorrect type: 06AP0000001OoEsMAK: [ContentDocumentId] error in test class

When making a test class I've ran into this assertion failure error. FIELD_INTEGRITY_EXCEPTION, ContentDocument ID: id value of incorrect type: 06AP0000001OoEsMAK: [ContentDocumentId] Here is my test ...
0
votes
1answer
20 views

Having an error List index out of bounds while testing contact trigger

Here is my Test class for trigger , after query for cases we get an empty list: @isTest private class TestContacts1 { static testMethod void testAddNewContact(){ Contact cont=new Contact(...
0
votes
1answer
1k views

Deployment, Code Coverage issue

I'm trying to deploy from Sandbox to Production. I am running into Code coverage error. The code coverage in the developer console says 92%. But Change set deployment to production fails with the ...
1
vote
1answer
25 views

how to return the result of a method?

i'm working on a test class and its giving a false positive. i wish to assert the result of the method being tested to see what the failure message is. my test class ends with this Test.startTest(); ...
0
votes
0answers
15 views

Writing Deployment Tests [duplicate]

I'm getting a Code Coverage error - at 70% code coverge. How can I write a test class for this extension? public with sharing class ShouldShowRingSection{ public ShouldShowRingSection(ApexPages....
0
votes
0answers
13 views

Testing schedulable apex class that sends an email [duplicate]

I am relatively new to Salesforce development (I'm an intern) and I am currently struggling with achieving 75% code coverage when testing a class that regularly sends out an email. I have included the ...
1
vote
1answer
29 views

sfdx force:apex:test:report is generating false PassRate as 100% though Failures present in the report

I have tried to run the apex tests and generate the test report on source deployed scratchOrg. report is showing Failure's count as 4 and Outcome as 'Failed' too, still shows the PassRate as 100%. ...
0
votes
2answers
38 views

How to avoid using SOQL with in For loop? [duplicate]

When i run the test code, it throws me message "System.LimitException: Too many SOQL queries: 101". How do i avoid using too many SOQL in this code. trigger GetObjLabel on Task (before ...
0
votes
2answers
875 views

How to check the overall Local test classes coverage in salesforce production org

we want to check our org test coverage excluding managed package test classes. we checked by clicking Run All Test Classes in Setup -> Apex Classes -> Run All Test. It's showing 61% but i am able to ...
0
votes
0answers
16 views

How to write a test class for a scheduleable class that sends an email? [duplicate]

I am fairly new to apex testing and am completely lost on how I am supposed to test a schedulable class that regularly sends an email. The class that I have written is below. It is very simple, and ...
0
votes
1answer
1k views

Apex job is already scheduled for execution

Hi I am getting apex batch already scheduled error while running test class. I don't know where i am going wrong. I am calling batch class from schedule class. Apex Class global class ...
1
vote
1answer
27 views

How can I test a class with @invocableMethod and SchedulableContext

I'm not getting coverage for this class, as it would be to test @invocableMethod global class CallFraudPreventionEventLogs implements Schedulable { global void execute(SchedulableContext ctx)...
2
votes
2answers
78 views

How do you know what to include in a test class for any given trigger?

I've had a fairly simple run in writing test classes, but am not sure if I'm doing it right or adhering to best practices. Below you'll find one of my triggers and its corresponding test class (100% ...
0
votes
1answer
45 views

Developing A Test Class [duplicate]

I've written Apex classes but this is my first time written a test class. I've read a number of sources and watch videos but I don't grasp the foundation to get a test to successfully cover my code. ...
0
votes
1answer
45 views

SFDX Test Coverage Calculation process is flawed and unusable

In my org we have several custom profiles, including community profiles. My sfdx project is structured in a way that the profiles are included in the file repository, but are not included when the ...
0
votes
1answer
475 views

UserId shows null .How to solve this problem?

I have created a resgistration page for community user so that whenever he registers his details in the page a user gets created in the org. Now, I have to write a test class for it . It is showing ...
0
votes
0answers
48 views

Unexpected exception while `Site.validatePassword`

I have the following autocreated class: and I need to write a test class for that. global class AutocreatedConfigSelfReg1587088360367 implements Auth.ConfigurableSelfRegHandler { private final ...
0
votes
1answer
18 views

Apex Test Failures on Installed Packages

I'm trying to implement an apex trigger, however, when I try to deploy, I'm getting errors when the Apex tests are running for installed packages we have in the system. I'm kind of lost here, in the ...
8
votes
8answers
5k views

Code Coverage report for all classes

Winter 14 release removed Code Coverage column from list of class and triggers. Did anyone found any (nice) workaround to check Code Coverage of ALL classes?
0
votes
0answers
27 views

Getting an error while creating unlocked package with --codecoverage option in salesforce

As per the current requirement new versions of packages can be created only buy running the sfdx force:package:version:create with --codecoverage option, however I am getting an exception related to ...
0
votes
1answer
29 views

Code Coverage Failure Your code coverage is 73%. You need at least 75% coverage to complete this deployment [duplicate]

I did run all tests in my sandbox and also tried to run them each individually - the overall avg code coverage is around 88%. However, when i try to validate my change set in prod, it is throwing an ...
0
votes
0answers
18 views

How to make a test class for a scheduled apex class? [duplicate]

I am new to salesforce and I have written test classes for only one class before which worked just fine. But how do I write one for a simple scheduled apex class. Here is the code below: global class ...
0
votes
0answers
15 views

MilestoneUtils - setup CaseMilestone in test class

I am am attempting to use the class from this help article but the test included did not provide full coverage (commented below) of the MilestoneUtils Class. https://help.salesforce.com/articleView?id=...
25
votes
1answer
8k views

Visual representation code coverage in VSCode

As per answer in this post, in order to get code coverage after running test classes from VSCode, we just need to add "-c" for the sfdx test command as below: sfdx force:apex:test:run -c -u myOrg -r ...
0
votes
0answers
23 views

Test Class for system.runas(user) not working for UserInfo.getUserId Coverage

Im stuck at 52% coverage of a vf controller that queries and displays timecards__c records of UserInfo.getUserId in a table. What is basically not getting covered is the if else statements after the ...

1
2 3 4 5
22