Questions tagged [failing-tests]

A unit test is code that is written and executed to test a specific portion/unit of source code. Tests that do not pass are considered failing. Tests that do not generate desired coverage are still considered to pass.

Filter by
Sorted by
Tagged with
2
votes
0answers
76 views

In a test class example of a Post Install script, sending an email and scheduling a class that performs an API callout

Scenario: In my example, as a part of the PostInstall (class implements InstallHandler) script I will be performing two actions; - sending an email to the installing User for the express purpose of ...
0
votes
0answers
24 views

MIXED_DML_OPERATION Error in Test Case with S2XUserMap

Before starting, I know about DML operations and the order they should be performed in for test cases. Please do not comment on that. These test cases succeed and have been succeeding in partial and ...
0
votes
1answer
1k views

System.DmlException: Insert failed. First exception on row 0; first error: FIELD_CUSTOM_VALIDATION_EXCEPTION

I wrote the validation rule to restrict the custom field picklist value it many test classes is getting failed because of that where and what line i can add into picklist value to cover the test ...
4
votes
2answers
238 views

'Guest users cannot be record owners' error during deployment of test class to production

I have increased test coverage of a class in QA Sandbox and I am trying to deploy that test class to production. When I run the test class in QA Sandbox, there is no error. But when I am deploying it ...
0
votes
1answer
38 views

Update own User in apex class [closed]

how may I update own user profile? I have below code I need update user field of runAs user @isTest static void xyzMethod() { Boolean errofFlag= true; User userXYZ= createUserWithProfile('...
0
votes
2answers
36 views

Rest API Test Class Problem

I am having some problem while testing my rest API Class. My main class is as mentioned there @RestResource(urlMapping='/ONB2__Subscription__c/*') global with sharing class SubsRecord { @HttpGet ...
0
votes
1answer
939 views

How to solve this deployment errors (Variable does not exist: isReadOnly)?

Trying to deploy package (big one) to a new org but all the tests failed with very weird errors: 1)line -1, column -1: Dependent class is invalid and needs recompilation: Class ClassName : Variable ...
0
votes
2answers
26 views

Apex Test Class Error on FinancialForce Sales Order Object

I've been trying for a few days to get this to work and but I've run out of ideas. I'm stuck. I can't get this test class to work. I get the following error. Trigger trigger efs_Sales_OrderTrigger on ...
0
votes
0answers
11 views

Test succeeds in packaging org, but fails during packaging

We are trying to avoid using globalDescribe as that can eat a ton of time in larger orgs. So we are trying Type.forName to get SObjectType and their describes without hitting the costly global ...
3
votes
1answer
626 views

Testing @future method Failed Assertion

I have some code that after inserting a task, calls an @future method to update some fields on the contact linked to that task (WhoId). This seems to work fine in sandbox, but I can't seem to get it ...
1
vote
2answers
726 views

Unable to insert group during tests - “Group Already Exists” with SeeAllData=False

Create a class to automatically add user to chatter groups. I wrote a test class to cover the code. The class is working fine and covering code if I add SeeAllData=true. Issue: If I remove seeAllData=...
0
votes
1answer
24 views

System.assertequal fails but debug log shows id

I have a test class that keeps failing on the last assert. The debug shows the newly created system record so not sure why it keeps failing. Location_c location = new Location_c( Name = '...
1
vote
1answer
43 views

SFDX Test Cases Failing only on Package Version Create

EDIT: If you are using a CI flow, ensure that it isn't creating profiles for you when running test cases. That was the main issue for me when using cumulusci. I am trying to deploy a package version ...
0
votes
1answer
38 views

After Update Test Class Is Not Committing Change

I'm working on a test class for an after update trigger and I am running into an issue where the change that is being done is not being comitted by the DML operation. For example, if I look at the log ...
14
votes
2answers
656 views

Salesforce 2020 release has blocked all Apex tests that use http mocking

We have 100+ tests failing now that our main testing sandbox has received the 2020 release. We can no longer deploy. We're getting many errors like Unexpected error: You have uncommitted work ...
0
votes
0answers
41 views

Confounded by Test Class Failing in Production but Passing in all Identical Sandboxes

I finally have to ask some other folks about this one. There's a test class from an (awful) unmanaged package in our org, and it has been there for a year and never been a problem, but suddenly it is ...
0
votes
1answer
25 views

Test class for updated field value

I have a class that is scheduled using CRON. I have created a test class and the test for the CRON is tested ok. However, the field update is not being tested and I cannot see why. Coverage is 57% ...
0
votes
1answer
22 views

How to create Case with Person Account in test class

@isTest public class TestDataFactory { public static List<Account> createPersonAccount(Integer numOfAccounts){ Id prsnAccountRecTypeId = Schema.SObjectType.Account....
0
votes
1answer
55 views

Assertion in the Test Class for ApexRest

I have a Apex Class which is exposed as a Rest API, the method is current void like below @RestResource(urlMapping='/SFDataAPI/*') global with sharing class SFDataAPI { @HttpGet global ...
-2
votes
1answer
51 views

Test Class to execute catch blocks [duplicate]

I have a Apex Class like below for handling the exception public class updateCaseRecord { @AuraEnabled public static void updateCheck(String caseId, String Status){ String msg = ...
4
votes
1answer
434 views

custom setting error when test classes run in parallel

I have a few test classes that fail but only when all the test classes are run in parallel.I'm using a hierarchy custom setting as part of the test code. In order to narrow down the problem I have the ...
0
votes
1answer
44 views

Date literals returning nothing in Apex Test

I'm doing the following in a test class. First inserting one record and then doing a record count to see that there is still only the one record in the DB. However when the query runs I get 0 records ...
1
vote
2answers
117 views

Test Class for the Apex Class with try Catch block fails

I am trying to write a test class for the Apex Class with try - catch block and this is my first time coding test classes. The Apex Class is like below which has trycatch public class ...
0
votes
1answer
26 views

Testing chained continuations

Im wondering if anyone has figured out a way to test chained continuations? I followed the documentation for how to essentially make two asynchronous callouts in a synchronous pattern. I can test the ...
1
vote
2answers
24 views

You have uncommitted work pending error

I am getting a "you have uncommitted work pending" error on a test. Normally this is caused by a DML statement before a callout. That shouldn't be the case here. However, the code runs fine and I am ...
0
votes
2answers
813 views

Validation rule and Managed Package

I have a Validation rule in ShippingPostalCode in Account Object. Validation rule check for US Standard format and field should be required. When I run runAllTest from Developer Console. Managed ...
-1
votes
1answer
25 views

Test Class for adding error message [duplicate]

@isTest public class ConvertTestClass { public static testMethod void test1() { Lead__c ld = new Lead__c (); ld.First_Name__c = 'Test'; ld.Name ='first'; ld....
0
votes
1answer
23 views

How to get rid of this System.ListException: List index out of bounds: 0 error in my test class [duplicate]

I am trying to create a new case with record type to cover the lines in my apex class but throwing the inbound error. please help me to cover the lines This is the full method public void ...
0
votes
0answers
10 views

I need help for Test Apex class [duplicate]

I got 52% with this test code, Please give me some advice to improve the percentage for passing. @isTest global class BLmainMock implements HttpCalloutMock { global HTTPResponse respond(...
0
votes
0answers
30 views

RecordType using Test.loadData in Testclass for account object

I am trying to export data in csv from one sandbox and trying to load the same data into Test class using loadData method. Currently , I am struggling in creating RecordType within Test class For ...
0
votes
0answers
39 views

Mixed DML causing test classes to fail to to Process builder

I have a Test class which was working fine but after a new process builder was created on user object to update a custom field created on user object, it started failing. In my test class code I am ...
0
votes
1answer
20 views

Batch callout error: Call out made it firstbefore DML

I have review similar questions, and all of them mention to do API before any DML similar question 1 and similar question 2 However, I am trying to do the API in the excecute, and I am still getting ...
0
votes
0answers
60 views

I don't know how to get 100% code coverage of this code

This code is used to prevent a case from being closed when it still has open tasks. When the user tries to close a case with an open task an error message pops up. Instead of using a Status from the "...
-1
votes
1answer
20 views

Help on System.ListException: List index out of bounds: 0 Error

I'm trying to write test code for my custom controller and got a new error that I haven't gotten before. My research so far has told me that misallocated and/or coming up NULL. Apex Class: ...
2
votes
1answer
10k views

How to bypass Validation rules when running apex class?

We have a managed package install in our org. When I create an opportunity, at a certain stage, I need to create a record of that managed package. For this we define validation rule for certain stages....
0
votes
1answer
30 views

SOQL injection issue on source scanner report

I am getting SOQL injection vulnerability on source scanner report. Please check one of the issue below. I tried string.escapeSingleQuotes() on query string. It is helping with removing this issue in ...
0
votes
0answers
24 views

Getting INSUFFICIENT_ACCESS_ON_CROSS_REFERENCE_ENTITY when mocking an Object using Stub API

I am mocking a routing rule object by using the JSON list below that has an ID of type Routing_Rule__c. The Test is about creating some rules and setting some flags that would cause the lead object to ...
0
votes
1answer
26 views

Workflow Task Error When Trying to Deactivate a User from a SandboxPostCopy Apex Test

I'm trying to deactivate a user in an apex test. But am getting an error that the user (that I just created in the test) in being used by workflow tasks. The class implements SandboxPostCopy and is to ...
0
votes
0answers
27 views

Apex Test Class is Failing - (System.QueryException: List has no rows for assignment to SObject) [duplicate]

I am brand new to coding and this is my first test class. I have spent hours trying to get it to pass. Apex Trigger That I am Testing trigger RenameTransaction on Financial_Transaction__c (before ...
0
votes
1answer
986 views

Insert failed. First exception on row 0; first error: PORTAL_USER_ALREADY_EXISTS_FOR_CONTACT, portal user already exists for contact: []

I am trying to insert portal user records and receiving this error System.DmlException: Insert failed. First exception on row 0; first error: PORTAL_USER_ALREADY_EXISTS_FOR_CONTACT, portal user ...
5
votes
0answers
63 views

Test fails with runAs, queueable and callout in specific org

Has anyone got an idea what could cause the following test to fail in one org and pass in another? The error is System.CalloutException: You have uncommitted work pending. Please commit or rollback ...
-2
votes
1answer
31 views

Error while saving a Test class

I have tried to insert session, speaker and session Speaker object in test class and I am getting error as "Unexpected token 'static'", Unexpected token 'testmethod', Variable does not exist: ...
6
votes
1answer
143 views

Unit Testing problem with Product2 records: A Product with this SKU already exists

I'm using the Product object and store the product sku within the StockKeepingUnit field. According to the Winter 18 release notes, this field is considered unique, which is totally fine and expected ...
2
votes
0answers
51 views

Apex test class enable product scheduling

Test Class Error: System.DmlException: Upsert failed. First exception on row 0; first error: FIELD_INTEGRITY_EXCEPTION, field integrity exception: unknown (scheduling not enabled on product): [...
2
votes
1answer
86 views

id's on list are not pulling into new list

I am running into an issue with my method for test where I insert contact records that are in a list and then try to pull the id's to associate it with a different list. When I do my debug for the ...
0
votes
1answer
31 views

Need help with Test coverage of batch apex error- System.InvalidParameterValueException:

I am trying to write a test class for the batch apex class, but i am getting an wierd error(System.InvalidParameterValueException: Provide the ID of a test-context sObject as the first parameter for ...
0
votes
1answer
33 views

Apex Test Class for custom Datatype

I'm literally pulling my hair out... I have this Apex Class: public with sharing class ProviderAPI_Datatype { Public Class Customer { @AuraEnabled Public String CustomerName {get;...
1
vote
0answers
35 views

'uncommitted work pending' callout exception thrown in *tests only*

I am converting a lead in the Execute method of a batch class, then making 2 callouts with those results in the Finish() method. It works gloriously and throws no errors. However, in the test ...
0
votes
0answers
28 views

Test class coverage only 30% stucked to pass controller [duplicate]

Apex class public class InspectionControllerExtension { public List<Inspection_Checks__c> Inspection_Checks {get;set;} public String currentRecordId {get;set;} //transient ...
-2
votes
1answer
32 views

System.DmlException: Update failed. when running test class

I am creating a test class and receive the following error when running the test. System.DmlException: Update failed. First exception on row 0 with id 0012o00002WUpPFAA1; first error: ...

1
2 3 4 5
8