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
0answers
11 views

INVALID_CROSS_REFERENCE_KEY, You can only assign users to permission set groups that have the “Updated” status

I'm struggling to assign a mocked permission set group in a test class. The test class fails because of the following error: INVALID_CROSS_REFERENCE_KEY, You can only assign users to permission set ...
-4
votes
0answers
19 views

Unit testing for value that need to return image value in a custom object

i want to test that if checkbox is checks, Attachment__c needs to contain image if else will get an error. Attachment__c is a rich text area. My test class: @isTest public class TestPraTrigger { ...
-2
votes
1answer
22 views

Code Coverage wont Push Tru After IF

I was trying to create a unit test for my APEX Class. But i was wondering the Test wont push thru after IF statement but i was using an existing leads (046933) for testing.
0
votes
1answer
18 views

How to cover the constructor in the test class of the salesforce

I have completed almost around 71 percent of my test coverage ,,but not sure how to cover the constructor in my test class can anyone help me out. Below is my constructor. public String oppId {get;set;...
0
votes
1answer
30 views

method does not exist or incorrect asignature?

If someone could help me, according to me I am doing the correct assignment of the method parameters, but it tells me that, if someone has an idea it would be very helpful. this is code to evaluate: ...
0
votes
1answer
23 views

system.runAs() doesn't throw an exception when user doesn't have permission

Let's say we have Boolean wasAuraException = false; system.runAs(TEST_DUMMY_USER) { try { DataWrapper data = MyController.getData('mockValue'); } ...
-1
votes
0answers
19 views

Multicallout mock response data is null

I am trying to cover a class in which each method has multiple callouts. For that, I have created multicalloutmock, but it works for the first response but for the second and third it is returning ...
1
vote
1answer
36 views

Unable to capture AuraHandledException in test class

Controller method: @AuraEnabled public static customObject__c getInfo(String recordId){ try { customObject__c rec = new customObject__c (); List<customObject__c > ...
0
votes
0answers
32 views

Unable to execute sfdx force:lightning:test:run -a jasmineTests.app in my scratch org from CLI on windows system

I am unable to execute this command sfdx force:lightning:test:install in my scratch org from CLI. It gives a warning. sfdx force:lightning:test:install Result: Warning: force:lightning:test:install is ...
-1
votes
0answers
17 views

I need help to start a test class about this apex class, any thing is good [duplicate]

public class ControllerFillerOrder { public ControllerFillerOrder() { } public class OrderFillerPerPrescrip{ @AuraEnabled public Id id; @AuraEnabled public datetime ...
4
votes
1answer
43 views

Deployment fails with: INVALID_CROSS_REFERENCE_KEY, You can only assign users to permission set groups that have the “Updated” status

Do CI deployments to a sandbox (Summer 21) that includes unit test code that mocks users and assigns them to a PermissionSetGroup. Unit test code has been working for months. The user mock factory is ...
0
votes
1answer
32 views

Not getting enough test coverage for schedulable batchable class

I'm updating some code written by another developer, and I'm having a problem getting adequate code coverage for the batchable, schedulable class. None of the test methods call execute(Database....
0
votes
1answer
32 views

Testclass for wrapper class implements Comparable and contentdocumentlink

I don't know how can I test my contentdocumentlink, in the log I got the information EXCEPTION_THROWN [18]|System.QueryException: Implementation restriction: ContentDocumentLink requires a filter by ...
3
votes
0answers
63 views

How to Test platform Event Trigger Flow

I have a flow which subscribes to a platform Event. This flow consumes the event and inserts a record. My test class is: Test.startTest(); Database.SaveResult result = EventBus.publish(...
0
votes
2answers
46 views

Need help with a mystery null pointer exception

I'm getting Null Pointer Exception from some recent code changes and I can't figure out where it's coming from. I've put ** around the new code. Any help would be appreciated! System.DmlException: ...
0
votes
0answers
50 views

Time based workflow slows down test execution

I have an old workflow for the custom object (let's call it Booking__c) in the org. It has a Time-Dependent Workflow Action based on once of the Booking__c's fields that sends an outbound message. ...
0
votes
1answer
36 views

Apex Test Class Question on Changing Account Owners

Situation: I've been given a task to "Change all child Contacts' Owners to the Account Owner from the parent Account, whenever the Account Owner changes." I've written the Trigger and ...
0
votes
2answers
31 views

How to access Custom Setting data in Apex Testing without using @isTest(SeeAllData=true)

I have written a test for a trigger handler that accesses a custom setting like so: Integer dueDateA = (Integer) (Dealer_Class_Due_Date__c.getValues('A').Days_to_Add__c); (in Trigger Handler) However,...
0
votes
1answer
19 views

How to set user profile Id in a trigger test

I am writing a trigger test class for a trigger that inserts a new task when the current task is saved. In the trigger I only want it to fire when the current user has a certain profile. Because of ...
1
vote
1answer
47 views

Debug Test and Debug All Tests for apex unit tests in VSCodedx

Does anyone have a link to the official documentation on this new feature added to VSCode-dx? Also, any tips on using this feature would be appreciated. What I've tried so far: I've tried the feature ...
0
votes
2answers
27 views

How to call a trigger in a Apex Trigger Unit Test?

I have an after insert/update trigger that on an object called Call_Report__c. The after trigger (upon save) sets the field of the Call_Report__c object. I'm not sure how to test it since I don't know ...
0
votes
1answer
20 views

Apex Class Test Coverage is failing at a particular line

My Apex class test coverage is just reaching 48% and failing at a particular line, not sure why it is happening as I am providing all the data that is necessary. My test class look like below. @isTest ...
0
votes
0answers
23 views

RE: Process builder condition not satisfying in test class

I have written test class where iam inserting the task records and then task status field is updating. Task taskRec1 = new Task(); taskRec1.AES_CNTR__UCID__c = 'abcd'; taskRec1.ARM_Property__c = ...
1
vote
0answers
36 views

Debugs show during insert on trigger but Debugs Not Showing in Trigger during Test of insert

TL;DR Test class will not show debug logs in the trigger, but executing an insert from dev console will show the debug logs. Problem Hello, running into some odd behavior around testclasses and ...
-2
votes
0answers
14 views

Please help me writing the test class for this trigger [duplicate]

trigger UpdatePreviousOwner on Account (before Update) { for (Account newRecord : trigger.new) { Account oldRecord = trigger.oldMap.get(newRecord.Id); if (newRecord.OwnerId != ...
0
votes
1answer
35 views

Getting code coverage error for class deletion (metadata xml) on deployment

When trying to delete a class together with its test class, I will receive a code coverage error (0% out of 75%) for both classes, the normal as well as the test class. How to reproduce: Assume I ...
1
vote
1answer
30 views

How to bypass managed package from Test class

Test Class : Account ac = new Account(); ac.Name = 'Test3'; ac.Type = 'Corporate'; ac.BillingCountry = 'DE'; ac.BillingStreet = 'First line' + '\n' + 'Second Line'; ac....
-1
votes
1answer
32 views

My Test Class is not covered [duplicate]

I cannot cover my test class ,its always on 18% or 12% ,i have a vlocity Class apex ,my class needs 3 parameters (inputMap) that we should pass in our test class , when i try to pass this parameters ...
1
vote
1answer
25 views

Q&A CustomExceptions and the DeveloperConsole

I have a process that I have been building for the last couple weeks that should only be run in Sandbox. I have gotten most of test coverage finished and reporting 100% coverage in Sandbox UnitTests ...
1
vote
1answer
19 views

How do I destroy apex classes in production if there are dependencies in both the pre and post deployment state?

I ran into an issue recently while trying to retire a project that shared an org with another project. To give an idea of the scope we are going from nearly 3000 unit tests to just over 400 after the ...
0
votes
0answers
28 views

Creating test coverage to a trigger [duplicate]

I have got help creating my first trigger and now I need an advise/help on writting the test coverage for the code so I can deploy to production. This is the trigger I want to create the test code to: ...
0
votes
1answer
34 views

Test class for queueable apex trigger handler with http callout

Whenever a new record of object abc is created, a queueable trigger handler makes http callout. My trigger handler is working fine and i am able to do what I intended, but when I test this trigger ...
1
vote
2answers
60 views

Q&A: Are there problems using System.abortJob() in Test Methods to Avoid Depth Max Governor Limit

Been posting here a bit around the ideas of Queueable Chains and test Methods. All of you have been very helpful. I had one last piece I ran into during deployment that I had to fix. The code snippet ...
0
votes
1answer
37 views

APEX Test Class Failure CPQ inserting more than 1 quote lines

I am currently on Summer 2020 CPQ. When creating test classes with more than one Quote line being inserted I am getting the below error? Any ideas as to why? looking through the debug logs the id ...
0
votes
0answers
13 views

Test Class for Importing CSV File [duplicate]

I new to Salesforce I am not getting how to write testclass for this class public class WageRegisterImportClass { public string Filename {get;set;} public Blob FileContent {get;set;} ...
0
votes
1answer
29 views

Static Variables and Unit Tests

I am trying to write a class to cache SObjects accross Trigger contexts. I understand that static variables will not persist across separate unit tests but mine don't seem to persist in any test. And ...
1
vote
1answer
26 views

How to count email invocation in @future method ? Limit check after Test.stopTest is returning 0; [duplicate]

I can't understand why I am getting 0 from Limits.getEmailInvocations(); that is run after Test.stoptest(). The method which is sending emails is @future annotated and run from trigger handler on ...
-2
votes
1answer
41 views

Help me to Test this Trigger . i Tried and getting 88% code coverage [duplicate]

trigger AccountToContact on Account (after Insert,after update) { List <contact> ConList = new List <contact>(); for(account ac:trigger.new){ for(contact con :[select ...
-3
votes
1answer
28 views

Test class have 'System.QueryException: List has more than 1 row for assignment to SObject' error [duplicate]

I have this error in my code. System.QueryException: List has more than 1 row for assignment to SObject May I know how to fix this? @isTest (SeeAllData=false) public class preventDeleteTest { ...
-2
votes
1answer
51 views

I am new to SalesForce development and don't have much understanding of test classes. Can anyone please help me creating test class for following code [duplicate]

public class GenerateFirstInvoices { @InvocableMethod public static void fetchOrderItems(List<Id> orderId) { List<OrderItem> oproduct = [SELECT Id, Next_Billing_Date__c, ...
0
votes
0answers
22 views

LWC JEST test for API callouts

I want to write JEST test for the following component: // JS file: HTTPCalloutInLWC.js import { LightningElement, track} from 'lwc'; // importing apex class to make callout import getCurrencyData ...
1
vote
1answer
33 views

Queueable Apex User Context in Unit Tests with System.runAs block not the same as productive code

I noticed that the running User Context of a Queueable Job in a unit test depends on who calls the Test.stopTest() method. Or rather when is the job to be executed in the unit test context. I wonder ...
0
votes
1answer
63 views

Too many queueable jobs added to the queue: 2 Testing Help Needed!

I have a problem on my hands around getting enough code coverage for the below code I am working on. The Scenario: When a CPQ quote is being worked and it is a primary quote I have a process builder ...
2
votes
1answer
43 views

Testmethod support for record-triggered flows with scheduled paths

I thought it would be a good idea to write some Apex testmethod automation to verify the scheduled paths on a record-triggered flow. But as far as I can tell, you can't do this (as of V51) Am I right? ...
0
votes
0answers
33 views

Cannot locate Apex Type for ID

Here is my code coverage. In the UAT environment, I don't get any error, but when I validate in production, I have an error. @isTest (SeeAllData=false) public class ...
2
votes
0answers
34 views

Can't run a test class on a class with ConnectApi.ManagedTopics as an Internal user OR as a Community user

I have an LWC which displays as a collapsible menu on an Experience Cloud Site. It's in a scratch org, and I'd like to deploy to production. The LWC is using a class that uses ConnectApi.ManagedTopics ...
-2
votes
1answer
40 views

How to test this method

public AbonnementControllerExtension(ApexPages.StandardSetController standardSetController) { this.stdSetController = standardSetController; this.subscriptionIds = new List<Id>();...
0
votes
0answers
64 views

Test class for a JsonParser in Apex

I'm a newbee with Apex and tryingto test one of my Apex class but just got a coverage of 25%. I don t even think it is really testing my class , because just some variable declaration and some if ...
-3
votes
1answer
33 views

Code Coverage for IF statement [duplicate]

May I know how I can create a code coverage for if statement code? Here is my if statement code: @AuraEnabled public static void submitFinalApproval(Id recordId) { //1. RS if(...
0
votes
1answer
50 views

Test Class failing for PendingServiceRouting

Working on a test class for PendingServiceRouting to be used invocable methods for a custom apex class. Although while inserting the PendingServiceRouting I am getting Insert failed. First exception ...

1
2 3 4 5
86