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

APEX Class / Test Class Code Coverage String Array [duplicate]

I'm experimenting with this Reusable Related List. I'm attempting to write a test class, but I'm getting 0% code coverage. What am I doing wrong with this test class? Am I just completely off-base? ...
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
29 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 ...
-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
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
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
0answers
41 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
17 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
28 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
46 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 ...
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 ...
1
vote
0answers
55 views

System.SObjectException: Field is not writeable:

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 ...
0
votes
1answer
24 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
2answers
28 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 ...
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
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
2answers
57 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
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....
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
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 ...
0
votes
1answer
20 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 ...
1
vote
1answer
28 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
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 ...
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
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 ...
0
votes
0answers
24 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=...
0
votes
1answer
43 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
0answers
21 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
votes
3answers
34 views

Test Coverage for Apex Class! On executing test class i am getting this error 'System.QueryException: List has no rows for assignment to SObject'

public without sharing class UserDetails { @AuraEnabled public static Account Details() { String UserId=UserInfo.getUserId(); String contactId=utility....
0
votes
2answers
25 views

i'm trying to write test apex but it gives me this error Illegal assignment from List<RL_Service_Detail__c> to Boolean

@AuraEnabled public static List<RL_Service_Detail__c> deleteContact(String conid) { if(conid != null){ RL_Service_Detail__c delContact = [Select Id from ...
1
vote
1answer
148 views

Code coverage mismatched while 2gp packaging

I am currently trying to deploy my final release package but error stats that i don't have minimum code coverage to promote package. But when I create scratch org and run all test I could see no ...
0
votes
1answer
24 views

Test apex class salesforce coverage code

i have a test class for salesforce @IsTest public class JsonGCloudApiApex_TEST { // This test method should give 100% coveragex static testMethod void testParse() { ...
0
votes
0answers
16 views

can I compare two fields like this in system.assert? I have to test a method that assigns the field Name to External id [duplicate]

@isTest public with sharing class AccountTriggerTest { public static testMethod void metodoTestBeforeInsert() { Account account = new Account(Name = 'account_Test'); insert account; ...
0
votes
1answer
30 views

Update Records from CSV TestClass [duplicate]

I'm running into an issue where my code coverage is lower than I'd like. I've hit a wall where the lines of the controller in the image below are not covered. I'm not sure how to get those lines to ...
0
votes
0answers
21 views

Code coverage aggregate result in test class for VF user input page [duplicate]

I'm having a hard tome covering the wrapper class for an aggregation in a test class. I'm only getting 48%. Can anyone see what I am missing? This Apex supports a VF page, where the user selects the ...
0
votes
0answers
20 views

Cover aggregate Result Wrapper Class in test class [duplicate]

I'm having a hard tome covering the wrapper class for an aggregation in a test class. I'm only getting 48%. Can anyone see what I am missing? This Apex supports a VF page, where the user selects the ...
0
votes
1answer
33 views

Test Class Coverage for Scheduled and Batch Classes

I am attempting to test a scheduled class that calls a batch class to update records. The following test class does not seem to find the Opportunity being created in the test class to pass that list ...
1
vote
1answer
19 views

Im getting “no viable alternative at character '&quot;'” while executing apex class for batch class

I have Created a Batch and test class for code coverage. However Im getting the following error message while executing the test apex. "no viable alternative at character '"'" Batch ...
0
votes
2answers
33 views

Custom Controller Test Class Coverage

I have a custom controller for a VF page that allows users to add and remove rows of records to create before they are actually created. My test class covers the addition of rows, but it does not ...
0
votes
2answers
29 views

Test Coverage for a HttpCalloutMock?

We have a test class, and it has @isTest and for some reason, salesforce is showing this class as needing coverage? Shouldn't this class be excluded from code coverage? @isTest(seeAllData=false) ...
0
votes
0answers
16 views

my batch brings records and identifies if they're acc or cont for a particular field. How do I test it?

@isTest public class ALN_Integration_BatchTest { public static testMethod void metodoTest(){ ALN_Integration__c rec = new ALN_Integration__c(); rec.First_Name__c = '...
0
votes
0answers
24 views

Apex test class code coverage issue [duplicate]

Iam having trouble with a code coverage issue in one of my apex class code coverage please find the code below. Apex class: public class Executeapex { public static void executethismethod(){ ...

1
2 3 4 5
21