Skip to main content
New
Stack Overflow Jobs powered by Indeed: A job site that puts thousands of tech jobs at your fingertips (U.S. only). Search jobs

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

I have added assert but while running test it is getting failed with this error ' Assertion Failed: Expected: null, Actual: Meeting Held'

Actual class @future (callout=true) public static void syncMeetingOutcome(String appId, String outcome){ ServiceAppointment sa = [SELECT AccountId, Id, appointmentType, SchedStartTime, ...
shivani's user avatar
  • 11
2 votes
1 answer
96 views

Why isn't my Salesforce test method returning null when querying a deleted record created in TestSetup?

I have a Salesforce test class with @TestSetup alongside two test methods. In the last method (testQueryDeletedRecord), I attempt to query a record that I deleted in a previous test method (...
Licytede's user avatar
2 votes
1 answer
76 views

Why SOQL automatically retrieves Owner data, although I don’t specify it in the request?

My Apex Test failed with the following error: Cannot specify both an external ID reference Owner and a salesforce id, OwnerId. It throws on attempt to Database.update a record. In the debug, I’ve ...
Duck The Developer's user avatar
0 votes
0 answers
29 views

My Opportunity Test Class is not calling the Opportunity Trigger that executes Opportunity Trigger Handler Class with Helper Class

I implemented the Trigger Framework. This is my Opportunity Trigger trigger OpportunityTrigger on Opportunity (before update, after update, before delete{ new OpportunityTriggerHandler().run(); } ...
raghavendra yadavalli's user avatar
1 vote
1 answer
41 views

Unable to lock row or deadlock issue

We have over 200 test methods in the org and since I started creating some test classes for my own Sandbox I have ran into issues with the following error but may vary by method: System.DmlException: ...
MrKnudz's user avatar
  • 13
0 votes
1 answer
44 views

Test Class Error for a Batch Apex Class

System.UnexpectedException: No more than one executeBatch can be called from within a test method. Please make sure the iterable returned from your start method matches the batch size, resulting in ...
Cloud Rizon's user avatar
1 vote
1 answer
64 views

Help with Apex Class and Test Class

I have an apex class that converts leads. The class works in the sandbox, with zero errors when using the test class and all works well when triggered by a flow in the sandbox environment. When ...
Chelsea's user avatar
  • 23
1 vote
0 answers
26 views

How can I Jest Test an LWC without relying on implementation details and assuming extended HTML does its job?

I have this test: it('handles errors from getDummyApiUsers', async () => { // Arrange const mockError = new Error('Simulated error from getDummyApiUsers'); ...
Brian Kessler's user avatar
0 votes
1 answer
47 views

How can I Jest test an Lightning Web Componet which leverages `connectedCallback`?

I have a Lightning Web Component "dapUserList". This is the HTML: <template> <lightning-card title="User List" icon-name="utility:user"> <c-...
Brian Kessler's user avatar
2 votes
1 answer
71 views

OpportunityFieldHistory in Apex test class (field tracking - NewValue)

i'm new to learning about Apex Test Class. I have business logic that needs to check the value of 'OpportunityFieldHistory' == 'ClosedWon' in a class to create a record (Contract). I'm making a test ...
Aparicio Jr's user avatar
1 vote
0 answers
26 views

I need simulate an exception for a test

I have a problem making a testclass. I need to simulate an exception for this class: public class ScheduleOmniAlta50 implements Queueable, Database.AllowsCallouts { private String body; ...
Gonzalo's user avatar
  • 15
1 vote
2 answers
37 views

visualforce test class ApexPages List has no rows for assignment to SObject

Despite having all records properly created, this test class is still throwing an error "List has no rows for assignment to SObject" in the line UpdateRecordWithLocationController controller ...
Bernardo Lira's user avatar
3 votes
1 answer
47 views

Reduce coverage noise in results when running Apex tests in VS Code

It used to be that when I ran Apex tests on a test class in VS Code, I would see one result per @isTest method. More recently (I'm not sure for how long), I started getting multiple results per @...
Matthew Souther's user avatar
1 vote
0 answers
21 views

How can I avoid Maximum stack depth has been reached on multi queueable single class? [duplicate]

I'm presenting the Maximum stack depth has been reached. error only on testing, how can avoid this error if I have created this nested queueable in just one class? This is the class used. global class ...
David Paucar's user avatar
2 votes
1 answer
64 views

Insert as User fails during test class

We have a class created with sharing that inserts a record as a user. I've created a test class and added a user, along with the related PermissionSet assigned to that user. However, when I run the ...
OztheWiz's user avatar
0 votes
0 answers
24 views

Is there any to automate the process of Quality assurance for data and campaigns in SFMC?

Currently, our team does a lot of manual work for Quality assurance to validate data in data extensions and checks on the campaigns to make sure they are going to the correct population. Is there any ...
kl2's user avatar
  • 343
1 vote
0 answers
53 views

How Can I Test The Basic AppMention Event Using Salesforce SDK for Slack?

I'm working with Salesforce Slack SDK, but I don't understand how can I test the app_mention event due to there are no examples and the documentation is not clear at all, I request help for test this ...
David Paucar's user avatar
1 vote
0 answers
36 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
  • 351
1 vote
2 answers
69 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
  • 25
0 votes
1 answer
55 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
48 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
38 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
  • 25
0 votes
1 answer
117 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
  • 25
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
60 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
46 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
447 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
  • 151
-2 votes
1 answer
94 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
91 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,497
0 votes
1 answer
24 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
142 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
144 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
  • 59
-2 votes
1 answer
48 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,884
0 votes
1 answer
104 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
72 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
89 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
  • 35
2 votes
1 answer
140 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
57 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
70 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
113 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
83 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
205 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
  • 687
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
317 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
194 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
56 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
56 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

1
2 3 4 5
95