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
16 views

Apex unit test - Error on ContentDocumentId(Missing field)

I'm practicing an apex unit test and getting an insert fail on ContentDocumentId and expecting a reconstruction. Any idea of this? @isTest public static void testUpdateResponse() { ContentVersion ...
user avatar
  • 99
0 votes
0 answers
18 views

Can anyone help me with the test class for below apex code .(Before update) [duplicate]

Trigger : when user tries to update the owner field it must throw error public static void Comm(List<Account> newLists, Map<Id, Account> oldMap ){ try{ User currUser ...
user avatar
-1 votes
0 answers
32 views

getting" unexpected token: from" error in below test class

@istest public class DateMathHelperTest { @isTest static void DateMathHelpermethod1() { Epix_Date_Math_Logic__c edml = new Epix_Date_Math_Logic__c(); //edml.name = 'test'; edml....
user avatar
0 votes
0 answers
24 views

Hi, Can anyone help me write test class for the following class [duplicate]

@RestResource(urlMapping='/InstallationWebService/*') global without sharing class Wx_InstallationWebService { @HttpPatch global static void updateContactGUID() { RestRequest ...
user avatar
-2 votes
0 answers
41 views

Please help to write test class for this? [duplicate]

public class SKUProductUpdatePaymentTerm { public static void UpdateSkuPaymentTerm(List<Product2> newList, Map<Id,Product2> oldMapProduct2){ Set<Id> SkuSetID = new Set<...
user avatar
2 votes
1 answer
37 views

First Apex Test Class | FIELD_INTEGRITY_EXCEPTION

Struggling with building my first test class so I can deploy an Apex trigger. The trigger converts an Opportunity/Opportunity Products into a Sales Order/Order Items. Receiving the below error message:...
user avatar
  • 23
-2 votes
0 answers
27 views

test class this batch with Trigger [duplicate]

Sorry how can i create a test class for these related classes? batch code : global class CreateRicontatto implements Database.Batchable<sObject> { String campaignId; global ...
user avatar
  • 1
0 votes
1 answer
20 views

Test Class for Custom Controller Example

Hi I'm hoping someone can help, I have a custom controller with a simple SQL statement that I can't seem to get a test class working, here is the controller: public class Example_Controller { ...
user avatar
1 vote
0 answers
27 views

Why schema of createable checking failed when the user clearly has the permission

I had this very simple code in my class: Interaction intToInsert = new Interaction(); if (Interaction.sObjectType.getDescribe().isCreateable()) { insert intToInsert; } When I run unit test ...
user avatar
  • 12.7k
1 vote
0 answers
21 views

Why does the Dev Console stop reporting All Tests coverage?

I have wondered this for a while now - sometimes when using the developer console, and running tests, the console stops listing the percentage of coverage next to "All Tests" in the upper ...
user avatar
  • 648
1 vote
2 answers
42 views

Deployed code to production without code coverage

My teammates have deployed a code to production without getting the class getting covered. and now I have added a small functionality and trying to push the code but deployment is failing is class ...
user avatar
0 votes
0 answers
40 views

Batch test class passing but not covering execute method

public with sharing class ContractBatch implements Database.Batchable<sObject>,Database.Stateful{ public Database.QueryLocator start(Database.BatchableContext BC){ return Database....
user avatar
  • 1
0 votes
0 answers
29 views

Getting full coverage for test class for boolean value? [duplicate]

This UserMigrationRoute class is migrating Community profile users to Partner profile and saving their username Password in userMigration object. I have really hard time writing test classes. I have ...
user avatar
0 votes
0 answers
14 views

Hi i have to write test class for following trigger handler class? can anyone help me in same. Code is mentioned below [duplicate]

public class ActionsToBeTakenTriggerHandler { public static void handleAfterUpdate(List<Actions_To_Be_Taken__c> atbtList, Map<Id, Actions_To_Be_Taken__c> oldMap){ if(atbtList !=...
user avatar
2 votes
1 answer
22 views

Find SearchQuery returning empty in test

I'm currently experiencing a problem where a regular old [SELECT ...] query returns results as expected, but a [FIND ...] does not. I have produced a simplified case below: @isTest public class ...
user avatar
-1 votes
0 answers
24 views

How would I write a test class for this Apex Class [duplicate]

I am new to apex and have managed to hack this together. public class ContactsListController { private String sortOrder = 'LastName'; public List<Contact> getContacts() { String ...
user avatar
2 votes
1 answer
55 views

When running tests during deployment, are tests ran in parallel?

Specifically, I deploy to my org using a command like this: sfdx force:source:deploy -u=<accessToken> --sourcepath ./src/main --testlevel RunLocalTests --json --wait 120 When doing this, do the ...
user avatar
  • 125
5 votes
1 answer
73 views

Summer 22: Deleting Public Group doesn't delete Shares in Apex Test

I have a test that was working fine for 2 years, unchanged, which is now failing post Summer 22. Ultimately, it deletes a Public Group and the assertion tests that any associated AccountShares are ...
user avatar
  • 1,057
0 votes
0 answers
24 views

Summer 22 Schedulable Test System.CalloutException

I don't quite know how to explain the behavior we're seeing. I have two test methods that test exactly the same thing (same inputs, same assertions). The only difference is that one schedules the job, ...
user avatar
  • 1,057
0 votes
1 answer
41 views

How to select an element inside a template if true in LWC Jest test?

I have an LWC app that has a lightning-input and a lighning-button. It fetches data from the server for a record whose ID is specified. I have successfully mocked the server calls. I am trying to ...
user avatar
-4 votes
0 answers
13 views

Want Test class for below class [duplicate]

global class WebAdmitDailyJob implements Schedulable,Database.Batchable,Database.AllowsCallouts { global void execute(SchedulableContext SC) { Database.executeBatch(new WebAdmitDailyJob(),...
user avatar
-1 votes
0 answers
16 views

how to write test class for the attachments [duplicate]

I'm facing problem to how to write test code for the attachment class.Please provide solution for that. Apex Class public class CaseControllerExt { private final Case acase; public Blob afile ...
user avatar
  • 1
0 votes
1 answer
34 views

How to write Apex unit test for a function that fetches meta data?

I have a function that returns the list of all custom objects that are currently present in the org, as listed below. @AuraEnabled public static List<String> getCustomObjectNames() { ...
user avatar
-3 votes
0 answers
28 views

I write a test class for my class but didnt get a proper code coverage [duplicate]

public class GenerateCostSheetCtrl { public String recordId {get; set;} public Cost_Sheet__c cs{get; set;} public GenerateCostSheetCtrl(ApexPages.StandardController controller){ ...
user avatar
0 votes
0 answers
24 views

Test class or Restclass http methods (POST/PUT/GET)

Can anyone help me to write the test class for my below Rest apex class: @RestResource(UrlMapping='/Onboarding/Accounts/*') global with sharing class rest_Accounts { @HttpGet global static ...
user avatar
  • 1
4 votes
1 answer
50 views

Unlocked 2GP - Is unpackaged Setup Object data available for tests?

Background I'm starting to get serious about breaking my org up into a collection of unlocked packages. I've made a few unlocked packages, but have encountered a bit of a roadblock when it comes to ...
user avatar
  • 48.3k
0 votes
1 answer
17 views

How to get Test Coverage on a Simple Wrapper Class

I'm trying to get a test class to cover a few wrapper classes I've created in Apex, but for some reason one of the wrapper classes doesn't gain coverage (0%) like the other one does (70%). I read in a ...
user avatar
0 votes
0 answers
23 views

Need help with code coverage for trigger and for loop [duplicate]

I'm new to Salesforce unit tests and am stuck on how to get coverage for the for loop below. The trigger inserts requirements based on their contact record type and which department they are in. I'd ...
user avatar
  • 1
0 votes
0 answers
37 views

How to get 100% test coverage for an apex trigger associated with an asynchronous callout?

I am looking for assistance on why 'zipCodeTimeZone.makeCallout(objLead.Id)' in both places on the trigger is not being covered/triggered by my test method while it is providing 100% coverage for the ...
user avatar
  • 1
0 votes
0 answers
13 views

test class coverage for User EscalationManager(string QueueName) [duplicate]

Public static User EscalationManager(string QueueName){ system.debug('@@@@@@@ QueueName '+ QueueName); User groupMember = new User(); if(checkRecursive.runOnce()){ Set<Id> ...
user avatar
-1 votes
0 answers
26 views

how to write test class logic for if else conditions? [duplicate]

Main class: global without sharing class VF_ExtendedCustomCalendarController { /***************************************************************************************** @description This ...
user avatar
  • 1
0 votes
0 answers
23 views

Why is my test class saying my users do not have access to the Task object?

So I've been having this issue with a test class where two of my tests won't pass due to an error saying INSUFFICIENT_ACCESS_OR_READONLY. Here is my trigger and test class. This is my first attempt at ...
user avatar
0 votes
1 answer
27 views

I have one batch class which updates Account Name to true. But Not getting updated data in Test class inside System.assertEquals()

public class CustomIterator implements Iterator<Account>{ private List<Account> accs; private List<Contact> conts; private Integer currentIndex; public CustomIterator(...
user avatar
0 votes
1 answer
25 views

Test Class Error for Apex Class meant to filter Quote Lines on a VF Email Template

I'm just starting out with Apex, really any SF development. I've been lucky enough to be able to learn and practice what I've been learning in real-life scenarios, but I've depleted my googling skills ...
user avatar
  • 5
-2 votes
2 answers
29 views

System.NullPointerException: null argument for JSONGenerator.writeStringField() test

I'm doing tests and I get the following error " System.NullPointerException: null argument for JSONGenerator.writeStringField() " I don't know exactly what I'm forgetting to do(I cannot ...
user avatar
0 votes
1 answer
23 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,889
0 votes
1 answer
28 views

Test class for HTTPCallout POST with Invocable Method from Flow [duplicate]

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
1 answer
24 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
30 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
  • 127
0 votes
0 answers
23 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
25 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
31 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
2 votes
1 answer
62 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
43 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 vote
0 answers
36 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
0 votes
0 answers
28 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
51 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
0 votes
1 answer
49 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

1
2 3 4 5
90