Last call to make your voice heard! Our 2022 Developer Survey closes in less than a week. Take survey.

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

How to properly test and assert an @restresource that do multiple API calls?

I am struggling to do a test class, mainly building a proper assert method based on the following @RestResource (at the end). This class have 3 different API calls (First API response an XML the other ...
user avatar
  • 1,899
0 votes
1 answer
20 views

Test class for HTTPCallout POST with Invocable Method from Flow

I'm still pretty new to this, and I've looked around and haven't been able to find the solution that combines everything like I'm trying to do. I've tried quite a few things, but here's where I ...
user avatar
0 votes
0 answers
29 views

"Do not support Web service callouts" Error while manipulating with string, Without any callouts

I have Test Class where I don't do any callouts, or requests or something else. I think The problem in Email field Which has record like "{id}@plaseholder.com". When I try to manipulate with ...
user avatar
0 votes
1 answer
21 views

Test class for a check if null method

I've been trying to write a test class for a method that checks if an object is null. @RestResource(urlMapping='/register-sequence') global class RestClassToTest { @HttpPost global static void ...
user avatar
0 votes
1 answer
28 views

Database query Test Class issue

Original code was Set<Id> crConIds = new Set<Id>(); if (!crConIds.isEmpty()){ crConIds = new Map<Id, Account>( [SELECT Id, Name, ContactInfo__c FROM Account WHERE Id IN :crConIds]...
user avatar
  • 125
0 votes
0 answers
20 views

Unable to Run Batch Test Classes. Please help me [duplicate]

I have written Batch Class which is working fine (batch class is written below), now I want to write its test class. The one I have written is not giving 100% code coverage (only 30% is covering), it'...
user avatar
0 votes
1 answer
16 views

Trying to make Batch update account test

i want to make test with this class, but i'm new with salesforce / Apex and i don't know what i do for it. global class Batch_Update_account implements Database.Batchable<sObject>,Database....
user avatar
  • 3
0 votes
1 answer
28 views

Test Class Not Covering Return [duplicate]

My test class doesn't seem to cover any of the return methods within my apex class, therefore only giving me 69% code coverage, and I can't deploy into production. Apex Class - Main public with ...
user avatar
  • 1
0 votes
0 answers
28 views

Account Id FOR Contact not updated

I created some Test-Class with 3 Accounts (Test Account 1/2/3) and 8 Contacts (Test Contact 1-8), with a Custom checkbox Active__c on Contact. Account 1---- Contact 1 & 2 (Only Contact 1 being ...
user avatar
2 votes
1 answer
28 views

How to use Cobertura and JUnit reporters with LWC Jest?

When creating a new SFDX project, the default Jest configuration for LWC unit tests looks like this: jest.config.js const { jestConfig } = require('@salesforce/sfdx-lwc-jest/config'); module.exports =...
user avatar
0 votes
1 answer
38 views

Need to insert New Event Date and time in Account Field (Event Date Time (manually created)) through Apex Class/Trigger [closed]

I am trying to insert New Event Start date/time and End date/time in Account object field (Event Date Time). Please help me to trigger code. Once New Event created, the Start Date/Time & End date/...
user avatar
-1 votes
0 answers
26 views

VS Code: Run Apex Tests Error The requested resource does not exist

I want to run all test in a Test Class in Visual Studio Code. I opened the .cls of a test class, then clicked 'Run All Test' and encountered this error: The requested resource does not exist I ...
user avatar
  • 113
1 vote
0 answers
17 views

Write Test Class for ContentDocument Trigger that sends email notification

I have the below code that fires an email notification to 3 related users from the account of the user that uploaded a document (this is for experience cloud users only). I'm struggling to get started ...
user avatar
  • 11
0 votes
0 answers
19 views

Why would deploying an Experience Bundle affect DateTime values in unrelated unit tests?

We have quite a few unit tests failing that do time conversions between time zones, but only when we try to deploy one specific experienceBundle through sfdx. We can remove that experience bundle and ...
user avatar
  • 41
0 votes
0 answers
32 views

COVER IF CONDITIONS [duplicate]

I have an apex class and a Test class already created. Now have added few IF CONDITIONS in my apex class, but I am unable to cover those in my TEST CLASS. APEX CLASS: global with sharing class ...
user avatar
-1 votes
0 answers
31 views

Test class for batch apex with crontrigger

So i have this Apex Class Apex public void execute(Database.BatchableContext bc, List<SObject> scope) { List<CronTrigger> triggers = (List<CronTrigger>) scope; for(...
user avatar
  • 1
0 votes
0 answers
27 views

Stub method from another class

I have stubbed class with name DataUtils and class which i am testing with name DataController. Method from DataUtils that is being called in DataController is web service callout. I cannot use ...
user avatar
  • 41
0 votes
1 answer
38 views

How to cover catch block in apex test?

Can you please tell me how I can cover the Catch block? public static Map<Id, User> getUsersMapByProfileId(Set<Id> profileIds) { try { return new Map<Id, User>([SELECT Id ...
user avatar
-1 votes
0 answers
69 views

Controller Extension Unit Test: 90% assistance reaching 100% [duplicate]

(WorkOrderController.apxc) - Visualforce Page Extension public class WorkOrderController { work_order__c request; public Id formId {get;set;} public string fileData {get; set;} public ...
user avatar
0 votes
1 answer
31 views

OrgWideEmailAddress and Messaging.SingleEmailMessage test class coverage

I have a class where I'm sending the email. My test class passing successfully but not covering Messaging.SingleEmailMessage and OrgWideEmailAddress. What I'm doing wrong here? public without ...
user avatar
0 votes
0 answers
9 views

Need to Create Test Class for Apex Trigger that Prevents File Deletion if Attached to Opportunity [duplicate]

Need to get Code Coverage up, and not sure how to write a test class for this. Code below. Thanks for your help! trigger PreventOppyFileDeletePROD on ContentDocument(before delete) { if (Trigger....
user avatar
0 votes
0 answers
12 views

Owner.Name is showing Null For Lead Record in Test Class [duplicate]

There are two test methods. First method insert the account and then queried the Correct Owner.name. And Second Method insert the Lead and then queried the null Owner.Name. Please let me know, how ...
user avatar
0 votes
0 answers
29 views

UNIT TEST TRIGGER - Coverage Test Trigger and using System.assertEquals [duplicate]

Hello, I'm new to salesforce and I have a problem with test coverage and System.assertEquals My coverage is insufficient And I get this as an error: Errors : System.AssertException: Assertion ...
user avatar
0 votes
1 answer
32 views

If I delete a Test Class out of Production, will there be any negative repercussions?

I was in the process of migrating some new Apex into our Production Org and this old completed unrelated Test Class kept on throwing an error. So after several hours, I was able to delete this ...
user avatar
-3 votes
1 answer
34 views

Code coverage not getting increased, getting "Attempt to de-reference a null object" [closed]

My code coverage is not getting increased. I'm getting "Attempt to de-reference a null object" error. Kindly help me in fixing errors! Constructor: public SampleDeliveryController() { ...
user avatar
-1 votes
3 answers
81 views

How to write a test class for this below code can anyone help me [duplicate]

I want to write a test class to achieve 100 % code coverage for this below code can anyone help me to solve this problem i don't know how to write a test class for using this trigger Trigger: trigger ...
user avatar
0 votes
0 answers
34 views

Insert JournalType DUPLICATE_VALUE exception in Loyalty cloud test class

We are working with Salesforce Loyalty cloud. In one of our test classes, we are setting up data, where we try to insert some records of the JournalType standard object coming with Loyalty cloud. ...
user avatar
0 votes
1 answer
17 views

Test for three callouts in one Queueable class

I have 2 callouts in one class. I use XML mock in static resources. How to provide the right fake XML to every callout? Thank you public with sharing class x implements Queueable, Database....
user avatar
  • 5
0 votes
0 answers
26 views

I am badly stuck in Test Class unable to get coverage more than 56%. Please help me [duplicate]

Test Class ClmSuiteCountrySettings__c testcs = new ClmSuiteCountrySettings__c(Name = UserInfo.getDefaultCurrency(), IsSampleLimitEnabled__c = true,IsSampleModuleEnabled__c=true); insert testcs; ...
user avatar
0 votes
0 answers
16 views

Create OrderPaymentSummary to Test Class

I am working on an OMS and when it comes to testing a return, I have managed to perform all objects up to OrderItemSummary and ReturnOrder. But when creating the OrderPaymentSummary and ...
user avatar
0 votes
1 answer
23 views

Metadata cannot be deployed from within a test [duplicate]

When trying to insert a custom metadata record within the test it gives me the following error @IsTest public class Object_1TriggerTest { @IsTest public static void Load_field_1_from_metadata()...
user avatar
1 vote
1 answer
25 views

Lead conversion in test class error - Invalid Converted Status

I have a test class that's doing a Lead conversion that's resulting in an "Invalid Converted Status" error. This is the part of the test class that's converting the lead: Test.startTest(); ...
user avatar
0 votes
0 answers
20 views

An error occurred in the apex test class [duplicate]

i have to pass the test class but the error is not resolving iam not bale to find the error can you please help what i have to do to pass this test class "message": "Method does not ...
user avatar
  • 1
0 votes
1 answer
17 views

apex test class, when testing, the error message is System.StringException: Invalid id:Class.speakerCRControllerTest.testSpeakerCRController: line 21

public without sharing class speakerCRController { //更新第三方信息 public static User u=[Select Id,Name from User where Id=:UserInfo.getUserId()]; @AuraEnabled public static string ...
user avatar
  • 1
0 votes
1 answer
30 views

Test class for a Batch scheduler

I can't understand how to write a test class for a batch scheduler. Here is my scheduler: global class UltimateParent18Digit_BatchJobScheduler implements Schedulable { public static String sched = '0 ...
user avatar
  • 21
2 votes
1 answer
86 views

CircleCI Tests Run Twice

I am running CI using Circle CI. Here is my config.yml: version: 2.1 general: jobs: build: machine: image: ubuntu-2004:202201-02 resource_class: large working_directory: ~/ci_app ...
user avatar
  • 275
3 votes
1 answer
83 views

Where is the error in my unit test for a Platform Event trigger that updates another record?

Context: I mostly work declaratively but can hack together a little Apex when needed. I am using Platform Events to change the user context to Automated Process to facilitate a post to Chatter not ...
user avatar
  • 35
-1 votes
1 answer
36 views

Code coverage at for loop does not cover code inside loop

Why is my apex test not getting the material inside the for loop? I have test data, and the method gets called. I just don't have coverage for anything inside the for loops as seen below. I included ...
user avatar
  • 29
2 votes
2 answers
61 views

Is it wrong to put 'insert' in test class with SeeAllData = true?

As the Vlocity documentation says, for Integration Procedure Unit Testing from Apex, we must use Salesforce seeAllData property. In my case, the ideal would be to insert Order data for the test unit. ...
user avatar
  • 79
0 votes
1 answer
63 views

How to do System.assert() check of a deleted record

I have a simple test class that creates and deletes an account record. With this class I'm testing my account merge functionality. @isTest public static void testUltimateParent18DigitIDonAccountDelete(...
user avatar
  • 21
-3 votes
1 answer
28 views

Test Class for RestResource gives "Methods defined as TestMethod do not support Web service callouts" error [duplicate]

Looking for some help here. I'm trying to write a Test Class for a RestResource I defined but am receiving the above Test Class failure. I was under the impression that you didn't need to define a ...
user avatar
-1 votes
1 answer
37 views

Getting error(TestMethod do not support Web service callouts) test class is failing because of the existing trigger on Job__c which making callouts

Not able to cover only Email messaging part in Execute method in batch class coverage is 62% Any help will be aprreciated. Batch class- global class SendEmailJobsAlertBatch implements Database....
user avatar
0 votes
1 answer
52 views

Test class data missing?

I have a couple of days with this test class. I added already all data necessary for my test class, but I'm getting only 69%. The problem is on the all "if", when I test my test class Its ok,...
user avatar
0 votes
0 answers
8 views

How to test asynchronous flow? [duplicate]

I have an asynchronous flow that updates a parent record when a child is created. It's async because I reference a roll up sum field on the parent in the flow. This works fine. I'm writing an apex ...
user avatar
  • 616
1 vote
1 answer
30 views

Testing a Field Sync utility without creating custom fields

I've created a utility in Apex that syncs a Lookup(User) field on Account or Opportunity with a specified Account or Opportunity Team Member Role, based on a custom metadata configuration. It's all ...
user avatar
  • 1,007
0 votes
2 answers
58 views

Do all unit tests have to pass in order to deploy a class to production?

I am the only developer in the new project and there are many classes that are not passing unit tests. I want to deploy only one class (which have only 10% of test coverage) How could I deploy this? ...
user avatar
0 votes
1 answer
38 views

How to deploy a batch class through change sets without a test coverage for that class?

I want to deploy only one class (batch) from sandbox to production and that class have only 10% test coverage but overall code has 80% test coverage. Would it be possible to deploy that class by ...
user avatar
0 votes
1 answer
62 views

Test class for an Apex trigger

I have an apex trigger which updates the description of cases with the concatenation of its child cases, if it has. If not, it fills the Description field with a default phrase. I'm trying to code the ...
user avatar
0 votes
2 answers
52 views

Creating a test class when trigger creates an Account with related Case

I'm learning Apex from David Liu's Apex Academy. I was reviewing my older triggers and noticed that this trigger no longer had coverage; I've updated my test class but it's not covering lines 5 - 8 ...
user avatar
0 votes
2 answers
34 views

How to specify identical records with SOQL?

I am writing a test class for a TriggerHandler called 'HasPotentialDuplicates'. I am checking to see if a duplicate record exists using a custom checkbox field I made called 'HasPotentialDuplicates'. ...
user avatar

1
2 3 4 5
90