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.
1,088
questions
0
votes
0answers
19 views
How to get over OrgWideAddress in Test Class [duplicate]
Is there any way to "skip" the lines or either create the data without using @SeeAllData=ture?
I didn't found a solution without using it.
Thanks.
0
votes
0answers
6 views
Wrappers Impact on Overall Code Coverage? [duplicate]
If a given wrapper doesn't have any method(even no get;set;) that class won't get listed under 'Overall Code Coverage' section in the developer console. Does this mean such Apex wrappers do not impact ...
-1
votes
2answers
33 views
Test “Try and Catch” block Code
I wrote a test class (please, see below) that covers most of my code except "catch" part of the code.
Please, help me to figure out what is missing in my apex test class.
public with sharing ...
-2
votes
0answers
24 views
How to write a test class for the below code! [duplicate]
trigger fieldupdate on Account (After Update)
{
if(Trigger.isAfter && Trigger.isUpdate)
{
Set<Id> AccountId_Set = new Set<Id>();
new list<contact>()...
0
votes
0answers
11 views
Test Class Error : FIELD_INTEGRITY_EXCEPTION, You cannot change the currency of an opportunity that has quotes related to it
I am trying to set opportunity SyncedQuoteId field with a quote id in a test class. The opportunity is only having one quote.
But I am getting the following error only on an one sandbox. On other ...
-2
votes
0answers
30 views
Need help writing test class for email Handler [duplicate]
I have written a class that logs the emails with attachments to related record. I have written a test but the following lines are not getting covered. Does anyone have any suggestions on how I can ...
0
votes
1answer
40 views
Test class is not covering response
Trigger
trigger UpdateRecordEventTrigger on dicecloud__UpdateRecord__e (after insert) {
String recordId;
List documentIdList = New List();
for(UpdateRecord__e thisUpdateRecord : Trigger.New){
...
0
votes
1answer
31 views
Trigger Testing Apex Class Not Testing Trigger
So I've written an Apex trigger for LiveChatTranscript, as well as a class that I think tests it; however Salesforce disagrees, and says my test has 0% coverage of my trigger. The trigger runs ...
0
votes
0answers
22 views
Does this unit test is correct? Shouldn't it throw an exception?
For a method:
@AuraEnabled
public static String login(String username, String password, String startUrl) {
try{
ApexPages.PageReference lgn = Site.login(username, password, startUrl);
...
0
votes
1answer
14 views
code coverage not covering if conditions
I am trying to get coverage for my apex code but apparently it is not covering a simple if condition. Any idea why?
Picklist_Class.getPickListValue('Case','Type');
0
votes
0answers
11 views
Need a help with creation of test class for trigger [duplicate]
I do not why but my precedent question was closed. So i post new question. I need your help to write the test class for the code below. I tried millions of time but nothing works, i reached the limit ...
-1
votes
1answer
29 views
Why can't I get code coverage for my trigger, even though I wrote a complete unit test? [duplicate]
I need help to create a test class for my trigger below:
trigger UpdateLeadLastMQLDate on Event (before update) {
Map<Id, Lead> leads = new Map<Id, Lead>();
for(Event record: ...
1
vote
0answers
20 views
Flow Interview on Invocable Process - how to get test coverage
Iām looking at a list of flows that donāt currently have code coverage obtained by running the following Tooling API SOQL:
SELECT Definition.DeveloperName
FROM Flow
WHERE Status = 'Active'
AND (...
0
votes
0answers
28 views
Test class for a login flow
I am trying to write a test class for a scenario where I have created login flow that is invoking a flow and that flow is invoking an apex method by passing current user Id.
Any idea on how I should ...
0
votes
1answer
38 views
0% coverage error on running specified tests while validating/deploying any change set in Production
I am getting 0% code coverage error while trying to validate changesets in production using run specified tests. I tried 3 unrelated deployments and all of them gave the same error. The changesets are ...
0
votes
1answer
17 views
Code Coverage for Case Comment Trigger
I have a trigger where when a case field called Macro is updated, it creates a case comment accordingly.
I'm trying to get code coverage, I only get 21%, and I can't seem to get the following lines ...
1
vote
1answer
88 views
test.starttest() and test.stoptest() not working
Please let me know how to resolve the below issue.I am new to salesforce,its still giving me an error Too many DML statements: 151.Using Test.starttest() and test.stoptest() is not working.
Test Class:...
0
votes
1answer
32 views
No code coverage on attachment test class [duplicate]
I could use some help with the code coverage on my class. The test class is not complete. I was trying to just get coverage on the program object and then work from there but I am not getting any ...
0
votes
1answer
27 views
Improve code coverage on model class
I am working on a making a callout to a third party webservice that provides information about some of the fields on the Accounts. The webservice response is huge and the corresponding model class is ...
0
votes
0answers
32 views
Overall code coverage showing zero after running test class
Every now and then I encounter the following issue after I run my test classes, they all marked as completed and pass, however the class in the section Overall code coverage shows as 0 (some of them ...
0
votes
1answer
29 views
Test Coverage Issue with Site.getSiteId()
I am unable to cover the below function in test class as siteId is always returned null
Id siteId = Site.getSiteId();
if (siteId != null) {
//Community user logic -- THIS IS THE PART THAT IS NOT ...
2
votes
1answer
28 views
Help Understanding How to write Test Class for Apex HTTP Post
So I've been through quite a few posts/questions already looking for enough information to have this "click" for me, but I'm still missing something. This is my first time working with ...
0
votes
0answers
42 views
Write a Test for extension HELP [duplicate]
Hi Im new working with apexcode and I Crate a Class in sanbox, but when I try to upload to production it says that my coverage code is 73%
this is my code
public with sharing class ...
3
votes
3answers
230 views
How to mock System.isFuture()?
I am writing some tests and I have encounter a problem. In my main app I have the following logic:
public static void main() {
if (System.isFuture()) {
System.debug('Is future');
// ...
0
votes
0answers
35 views
Help with Code Coverage for Milestone Completion Trigger [duplicate]
I have minimal Salesforce development experience and I am struggling with getting a test class built to cover 2 triggers.
In the following Salesforce help article there are 2 triggers, 1 to auto-...
0
votes
0answers
31 views
Case Milestones not created when testing apex class
Recently I stumbled upon problem getting code coverage for Apex code that evaluates case milestones by their target date values. When trying to create case in test class it does not create case ...
-1
votes
2answers
31 views
What is test class for below code? [duplicate]
public class UtilityClass {
public static String getDescribedObjects( List lstSObjectType ) {
// Globally desribe all the objects
Map<String, SObjectType> globalDescribe = Schema....
0
votes
1answer
44 views
CPU time limit using Batch Apex
I am working on finishing up my Test Class to cover a new Batch Apex trigger I am writing however when I try to run the test I get the error: System.LimitException: Apex CPU time limit exceeded
I ...
1
vote
1answer
38 views
Test Class Id Error
I trying to get better and have built a trigger/test class using my knowledge I have learned however I am running into an error with the test class that for some reason I just cannot resolve and ...
0
votes
1answer
43 views
How do I write a test class invoked from a flow? [closed]
I'm really struggling with writing my first test class for an Invocable method. It's an apex class that's fired from a flow. I've read a bunch of posts and examples but I haven't seen anything that ...
0
votes
1answer
356 views
LWC Error: Cannot set property 'textContent' of null
I have an lwc class with the following HTML:
<template if:true={showModalButton}>
<lightning-button class="right-col-button" variant="base" label={modalButtonLabel} ...
0
votes
1answer
21 views
System.TypeException: Invalid conversion from runtime type List<ANY> to Map<String,ANY>
I'm writing test class for one of my method and getting this error:
Method:
public String onLoadLog(String loaddata) {
Map<String, Object> LogData = (Map<String, Object>) JSON....
0
votes
2answers
50 views
test class passing but not covering execute method
I have coded a batch class and am now working on the corresponding unit test. I believe I've inserted all the objects I need but none of the actual execute method is being covered, despite the test ...
1
vote
0answers
25 views
Even with KnowledgeUser I get: Be sure the action is valid for the current state of the article, and that you have permission to perform it, exception
I have the below test class:
@isTest
public static void batchManagementDraftTest() {
User u = TestDataFactory.createUserWithRoleLeader();
User u2 = TestDataFactory....
0
votes
1answer
23 views
Passing parameters from test methods
I am facing difficulty in passing parameters to apex method from test method. In apex method, I am getting parameters from my VF page.
Example of Apex Method:
public PageReference create_contact()
{
...
0
votes
1answer
77 views
Batch class start method returning null, even after a record has been inserted in the test class
I have a batch test class:
@isTest
public with sharing class TestBatchManagement {
@isTest
public static void batchManagementTest() {
User u = TestDataFactory.createUserWithRoleLeader()...
0
votes
0answers
29 views
Test method issue for PageReference method [duplicate]
I am trying to to write a test method for my custom apex controller which contains a constructor and multiple PageReference methods, all returning null. I am trying something like this:
@isTest
Public ...
1
vote
0answers
31 views
Test class for Einstein OCR service
We are hitting Einstein OCR to predict an image. When we tried to write test class for it we are always getting this error in developer console.
Go to Setup and Configuration on the Einstein Admin tab ...
0
votes
2answers
26 views
Using MultiStaticResourceCalloutMock [duplicate]
I am working on a class that makes a callout to a third party API. The third party API needs to be authenticated with a OpenID Connect Auth token. So, in my class, I am making a callout to the OpenID ...
0
votes
0answers
25 views
how to write test class? [duplicate]
how to write test class for this class
Multiple objects are included to this method. i don't know how to its cover
public static void createAutoIndex(List<EmailMessage> emList, Map<Id, Case&...
-3
votes
1answer
41 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 {
...
0
votes
1answer
23 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
32 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
51 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>,...
0
votes
1answer
60 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 ...
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
34 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
48 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 ...