Questions tagged [unit-test]

A unit test is code that is written and executed to test a specific portion/unit of source code. Unit tests are class methods with the testMethod modifier or @isTest annotation and are usually placed in separate test classes annotated with the @isTest annotation. Code that is executed by unit tests is considered covered. At least 75% of an organization's codebase must be covered by unit tests and every trigger must have at least 1% unit test coverage.

Filter by
Sorted by
Tagged with
1 vote
0 answers
21 views

Create Opportunity & related OpportunityHistory Test Data

I've written a batch job which queries a bunch of Opportunity records and their related OpportunityHistory records to capture data from the history records on the Opportunity. This is working as ...
VaroutSP's user avatar
  • 331
-2 votes
0 answers
33 views

test coverage with try catch

public static void sendAlert(Id appId , String emailType, Boolean futureCall ) { sendAlert(appId, emailType); } public static void sendAlert(Id appId , String emailType ) { String ...
shivani's user avatar
0 votes
1 answer
35 views

Unit testing generating and sending emails with fflib-Apexmocks

I am currently struggling to write a unit test for a method in my domain class, and I'm finding it challenging to understand the logic, especially since I'm new to using the fflib-Apexmocks library. I ...
selman's user avatar
  • 15
0 votes
1 answer
40 views

JEST Testing for wire methods

import { createElement } from 'lwc'; import ConversationWebComponent from 'c/conversationWebComponent'; import {setImmediate} from 'timers'; import getConversationData from '@salesforce/apex/...
Munib Ahmed's user avatar
0 votes
0 answers
31 views

Code Coverage issue for my scheduled class [duplicate]

In have been written a schedule apex class to send an email to users where the opportunity not modified by 14 days, the class is working fine I am writing the test class which it is not covering the ...
Naveen Varada's user avatar
0 votes
1 answer
40 views

create a new record type for an object inside testing environment using apex

I have a function that fetches record types for a list of sObjects. It adds each record type, along with the sObject name, to a resultMap if it exists. I need to create a mock record type for testing ...
Komal Riaz's user avatar
0 votes
1 answer
31 views

How to test Batch Apex Heap Size Logic?

I have a batch class that implements Database.Stateful and it is filling a Map collection at the execute method alongside other things. This map is then utilized to send emails related to the records ...
selman's user avatar
  • 15
0 votes
1 answer
44 views

Mocking a Batch class?

Is there any way to mock a batch class for unit testing and predefine the scope passed to execute method? I am using a selector class method for Database.getQueryLocator at start method. public class ...
selman's user avatar
  • 15
-2 votes
0 answers
29 views

Can you please help to write Test case for InvocableMethod [duplicate]

Hi can you please help me to write test case for InvocableMethod, which sends Emails. I wrote a test case but the coverage is 0%. Class: public class SendMassEmailsToDecisionMakersAction { public ...
Apex Lamer's user avatar
0 votes
0 answers
13 views

Trying to create a test class for an Apex class with invocablemehtod [duplicate]

I have the following Apex class public class sendAnEmailChk { @InvocableMethod(label='Test' description='sends an email') public static void sendEmailWithAttachment(List<id> ...
Sam Biz's user avatar
0 votes
1 answer
50 views

Error on executing test class: System.DmlException: Insert failed. First exception on row 0; first error: CANNOT_INSERT_UPDATE_ACTIVATE_ENTITY

I have written a test class for the below mentioned triggerhandler class but getting the below error after running the tests: System.DmlException: Insert failed. First exception on row 0; first error:...
Sai Bhargav's user avatar
0 votes
2 answers
42 views

Test Class coverage on execute method of Batch Apex which is Scheduled to run at specific interval of time

I have a Batch class, which queries Lead records that were created 1 day before. I have created a custom Label 'More_Than_1_days' which has the value 1. I was using this custom label in that batch ...
Mohd hasim's user avatar
-2 votes
1 answer
37 views

System.QueryException: List has no rows for assignment to SObject - In Test Class

I'm Getting an error in running of Test Class but the functionality in class working as expected: System.QueryException: List has no rows for assignment to SObject The below query is giving an error:...
sekhar's user avatar
  • 19
0 votes
1 answer
59 views

How do I get Apex Code Coverage in Visual Studio Code to show color highlighting and percentage after running a TestSuite?

I am using the most updated SF plugin, Visual Studio Code and sf-cli against our internal sandbox environment. I have an Apex class that has tests in multiple files. I would like to run a test suite ...
Shaun's user avatar
  • 119
-2 votes
1 answer
85 views

Getting System.TypeException: Methods defined as TestMethod do not support Web service callouts

I have implemented everything properly but still I am getting this error. Give you my code for your reference. Please help me. //code for Combined_Test @isTest private class Combined_Test { @...
karan bilakhiya's user avatar
0 votes
1 answer
49 views

Do mock classes need @IsTest?

Should mock classes always be annotated with @IsTest? Are the reasons not to annotate them? The reason that I'm asking is that I stumbled upon a mock class with a custom constructor for testing that ...
Semmel's user avatar
  • 2,413
0 votes
1 answer
21 views

How can I cover the Exception in this code in Test coverage(test class)? I did everything but my knowledge is not enough please help me :(

public with sharing class SampleClass {//EV GS R-3209 07122021 @AuraEnabled public static String insertCase() { String mReqRTid = Schema.SObjectType.Case....
Jay Locker's user avatar
1 vote
2 answers
88 views

Salesforce Trigger Handler Framework - Testing the Trigger

I'm looking at implementing a trigger handler framework and I understand the benefits of separation, dispatching to helpers from the handler, etc. What hasn't been obvious looking over the materials ...
almc's user avatar
  • 13
1 vote
2 answers
125 views

Is there a CLI command to find all Test classes associated with a certain Apex class?

As the CLI runs tests before deploying an Apex Class, it has to know which tests are associated with a certain Apex class. Is there a way to retrieve a list of test classes that are associated with a ...
Z0q's user avatar
  • 155
-2 votes
1 answer
33 views

How to use Mock HTTP in a Test Class [closed]

I've never written a test class which involves an API callout and I'm just now finding out I will get a "Methods defined as TestMethod do not support Web service callouts" error. I ...
Zoom_v's user avatar
  • 3,860
0 votes
1 answer
100 views

Test Class Data Setup - Cant Access Data outside

Within my test class's "setup()" method, I am calling a class that creates and inserts Salesforce objects and the necessary related objects to create that object (if any). @TestSetup static ...
plowrey's user avatar
0 votes
0 answers
44 views

Test ExpressionSet from Apex Unit test

I have below in the code On Case create/update- I have a flow that calls express set I am inserting Case from Apex class I have written Apex test class which inserts Case What's happening - ...
love gupta's user avatar
0 votes
0 answers
81 views

Test Methods With No Assert result

I'm using the Salesforce code scanner to validate my package and am seeing a lot of "Test Methods With No Assert result" messages for methods that do contain asserts, and test methods run ...
ravent's user avatar
  • 23
2 votes
1 answer
124 views

SOSL query the encrypted text field is possible but NOT in Apex test class?

I created an classic encrypted text field called "encryptedPIIData__c" in User object and added the User data. I created a function that is able query out via SOSL based on the encrypted ...
compski's user avatar
  • 1,352
0 votes
0 answers
41 views

How do I create Sales Cadence Records in Trigger Apex Test Code on ActionCadenceTracker obj

I have a trigger ActionCadenceTrackerChangeTrigger on ActionCadenceTrackerChangeEvent (after insert), and I'm trying to get its coverage above %71, but I'm not able to insert a tracker so this If ...
Nabil's user avatar
  • 11
0 votes
2 answers
66 views

Issue creating test data for a method using userInfo.getUserId()

Im having issue testing 3 of my methods (which are all working properly on my community site), they all use the same query with userInfo.getUserId() to retrieve user Id. For example : public without ...
NilPoc's user avatar
  • 3
0 votes
0 answers
85 views

How to use Apex Mockery Lib for simple scenario?

Was wanting to use Stub API for mocking test for some time but had been too busy to try it out. I saw some devs recommending FFLib but I find it too heavy a framework for most SF envs. So looking for ...
compski's user avatar
  • 1,352
1 vote
1 answer
72 views

Test System.Limit Exception Handling with BatchApexErrorEvent

I want to provoke a System.LimitException in a test method, so I can test BatchApexErrorEvent trigger that is supposed to handle uncatchable exceptions like CPU-Timeout etc. However the LimitException ...
Robert Méndez's user avatar
0 votes
1 answer
95 views

How do I create or access a static resource in my method when test is running

I have an apex method that reads static resource files and attaches a copy to each new record created. It executes this line and the static resources exist so it works fine. list<StaticResource> ...
Ohmicron's user avatar
  • 672
0 votes
1 answer
50 views

Apex trigger test object is only changed, if value is changed within the @isTest scope

I have this test where I need to set a boolean (Requires_number__c) on a WebCart. This boolean is normally set via a trigger, in case a specific cartItem is added to the cart. The problem I am ...
I am not Fat's user avatar
0 votes
2 answers
48 views

Unit Test Code Coverage 72% Help [duplicate]

I have created a test class for an apex class and code coverage is only at 72%. I am looking for any assistance you can provide, to increase it to 75%+. Uncovered lines: 5/18. The lines are within the ...
Sugi's user avatar
  • 3
0 votes
1 answer
207 views

Error while creating a test class - DML operation Insert not allowed on Survey [duplicate]

I have created a apex batch class to create survey invitations, subject records & send the unique survey links to participants. Trying to write a test class to cover it by inserting a surveybut ...
SMorse's user avatar
  • 39
0 votes
1 answer
116 views

Unable to fetch accountId of User in Test class

I am stuck in scenario while writing logic for my Test class. I am not able to access Contact.AccountId of User created in test case. I have created a TestUtility class for creating the community user....
user15754268's user avatar
0 votes
1 answer
55 views

Need help increasing the code coverage for this trigger [duplicate]

I'm a newly hired Salesforce admin and I've been struggling to deploy this trigger since this code is completely new to me. I've been trying to deploy a new version of a trigger with, at most, 10 ...
Humberto Cárcamo's user avatar
0 votes
1 answer
51 views

ContentDocumentLink Trigger successfully blocks file upload on Org but fails in Dev Console

I want to block file uploads (ContentDocumentLink) on a FundingOpportunity object when status is Canceled or Closed. It works fine in the org, but it fails when I tried it on Dev console. A File is ...
ash's user avatar
  • 1
0 votes
1 answer
41 views

force:apex:test:run throws error in CI: "No tests were able to be executed on the org. Please verify that the source code has been pushed correctly"

Upon attempting to run Apex tests via CI using command "force:apex:test:run" in a packaging org, I get the following error: "An unknown exception occurred. No tests were able to be ...
Andrei Migachev's user avatar
0 votes
1 answer
58 views

Apex - 0% Code Coverage!

I've developed a trigger that converts a currency field, Amount (i.e. $1,000) into words, Currency_text__c (i.e. One Thousand). This is achieved via Salesforce a 'FundingAwardTrigger' on the ...
Jean-Se's user avatar
  • 55
0 votes
1 answer
48 views

"Connection was cancelled here" error NOT related to parallel testing

I have a simple Custom VF Controller with a constructor and a single method, and an accompanying test class which I have inherited. Nothing special; the controller queries some records and inserts ...
Jason Clark's user avatar
  • 11.9k
1 vote
1 answer
77 views

Apex Mocks - Verify that child is correctly related to a previously registered parent in Unit of Work

I have code where in the same Unit of Work I'm inserting a record and a related record, for example an Account and Contact. Account acc = new Account(Name = 'Test acc'); unitOfWork.registerNew(acc); ...
Kamil Pilarski's user avatar
0 votes
1 answer
285 views

B2B Commerce: Error getting or creating webcart

I'm trying to run some apex tests in our Webstore (there's just one in the org), in a scenario that the test class creates dummy user/account/contact/buyer group/products/cart to finally test some ...
Diego Catharino's user avatar
0 votes
2 answers
79 views

Can we compare a currency field and number field in system.assertEquals ...If yes ...How?

@isTest public class HandlerClassTest { @isTest public static void InsertTestMethod() { List<Account> accList = new List<Account> (); for(Integer i=0;i<5;i++) { ...
Akash's user avatar
  • 1
0 votes
1 answer
38 views

Test class for batch with another class called in it: Batch has 100%, but called class only 24% coverage [duplicate]

Batch class: public class BatchClassForCustomer implements Database.Batchable<sObject>{ public Database.QueryLocator start(Database.BatchableContext bc){ string query='...
Pratik Bokade's user avatar
0 votes
0 answers
46 views

Test class for @future method called by trigger not working (Methods defined as TestMethod do not support Web service callouts) [duplicate]

I have a trigger on Account that makes a call to an apex class: trigger AccountAddressTrigger on Account (after insert) { Id patientAccountRecordTypeId = [SELECT Id, RecordType.DeveloperName FROM ...
happyLion's user avatar
-1 votes
1 answer
20 views

Unexpected Tokens on Test Class for Apex Trigger: What am I doing wrong to create a test class for this Trigger trying to deploy to Production?

@isTest public class LeadRemovalTestClass { Static testmethod void updateRecord() trigger UpdateLeadOnRemoval on ActionCadenceTrackerChangeEvent (after insert) { ...
Mark5000 Crimper's user avatar
2 votes
1 answer
468 views

Test class in managed package is failing with Internal Salesforce Error: 415122577-6508 (-1655455180) (-1655455180)

When Managed package metadata is deployed to a scratch org and tests are run by automated pipeline, one of the test method in a test class is failing with following error "Internal Salesforce ...
Vasudev Pai's user avatar
3 votes
2 answers
200 views

Is There a Best Practice for Associating Apex Test Classes to Apex Classes?

About a year ago, I developed an Apex project that involved a trigger/handler. It included the trigger, a trigger handler class, several helper classes, and a test class. All went well. Recently ...
Ron Van Aken's user avatar
0 votes
1 answer
105 views

Running and filtering reports in Apex

I just spun up a brand new Dev Org (00DHp000002yxab), and copy-pasted code from this Salesforce support article: https://developer.salesforce.com/docs/atlas.en-us.apexcode.meta/apexcode/...
Charles Howard's user avatar
0 votes
0 answers
111 views

Test Class - Testing Updates

I had to add a couple of updates to my class and now I'm only at 69% code coverage. How do you write tests when you are simply doing an update? I feel like I'm overthinking it, but then maybe not ...
Heather's user avatar
  • 51
-1 votes
1 answer
99 views

Test Class for method with List<List<Ids>>

Hi Salesforce Experts, I have a created a apex method which is invoked from a screen flow to mass approve records selected by the user from the data table component. This is working as intended, ...
Sugi's user avatar
  • 3
0 votes
1 answer
109 views

Lookup query exception while using USER_MODE

I am trying to create a 2GP package. But whenever I try to create a version by running and validating all test classes and metadata, the test class fails and shows such an error. "common.apex....
AJITHKUMAR VP's user avatar

1
2 3 4 5
95