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

Test class not covering code in batch apex

HI I created a batch apex but my test class is not covering the entire code, not sure where i am going wrong. Looks like query in start method is not returning any test records which i created. Please ...
1
vote
1answer
196 views

Test class Of a Trigger

Here is the trigger trigger UpdateNumberOfQuantityInstallments on OpportunityLineItem(before insert) { List<product2> lstProduct2 = new List<product2>(); for(OpportunityLineItem oli : ...
0
votes
0answers
2k views

Test Class Failure : DUPLICATE_VALUE, duplicate value found: Unique_Record_ID__c duplicates value on record with id:

I am facing an issue with a test class. Getting the following error (System.DmlException: Upsert failed. First exception on row 0 with id a0xuxuxuxuu..; first error: DUPLICATE_VALUE, duplicate ...
0
votes
1answer
159 views

RecordTypeId is invalid even with SysAdmin profile

Trying to deploy some changes between two sandboxes, I'm facing the following error: System.DmlException: Insert failed. First exception on row 0; first error: INVALID_CROSS_REFERENCE_KEY, ID do ...
-1
votes
1answer
108 views

test class showing system.Assert exception ,provide solution

@IsTest public class Incrementtrigger_update_Test { Public Static TestMethod Void Test1() { Test.StartTest(); SCSCHAMPS__Appointment__c app =new SCSCHAMPS__Appointment__c(...
1
vote
1answer
634 views

Failed apex test class preventing deployment

I am receiving the following error message when trying to deploy a couple of unrelated classes and triggers. Does anybody have advice for me on how I can pass it, or should I get in touch with our ...
0
votes
1answer
664 views

Test class on lead conversion trigger is not working

I have created a trigger on lead conversion to create contact of custom contact filed in lead. I have created some custom fields on lead object to capture alternate contact details apart from main ...
2
votes
0answers
100 views

Why Field Accessibility Check is broken in a Managed Package?

my code has a centralised class which is responsible for all DML operations. This class before inserting / updating / deleting a record is checking: 1, if the object is accessible for the current ...
0
votes
1answer
2k views

CANNOT_INSERT_UPDATE_ACTIVATE_ENTITY on Apex Test Class

I've been trying to create and implement an Apex Trigger/Apex Test Class for the Asset object to automatically populate an Asset custom lookup field, "Partner_Client__c", with the same information as ...
1
vote
1answer
79 views

Apex List Test Failing in Prod But Passes In Sandbox and if Directly Queried

I have a simple getter inside my class that returns a list of cases depending on who the currently logged in user is (in my circumstance this is a Community User). When i run the code in my full ...
0
votes
1answer
276 views

How to write test case for catch in following method?i want to cover catch block in code coverage [closed]

@RemoteAction public static List<Account> GetAccountOwnerEmail(String AccountId) { List<Account> lstAccount = new List<Account>(); String [] conFields = new string[]{'Email'}...
1
vote
2answers
93 views

Regarding Test Class in Salesforces [duplicate]

How to Write a test Class for Wrapper Class or Dto Class,how to call Wrapper Class in Test Class Please anyone Provide with Sample Example
0
votes
1answer
53 views

Regarding apex class to Test Class

I have A Given Sample Apex Code @HttpGet global static String doGet(){ RestRequest req = RestContext.request; RestResponse res = RestContext.response; try{ ...
0
votes
1answer
135 views

Unit testing: Assigning a Custom Obj Auto-Number to String Variable?

I have been trying to successfully compile a Test Class for triggers that auto-insert a DML_Log__c upon a specific sObject type being deleted, and an error keeps getting thrown: Expression cannot ...
1
vote
1answer
77 views

HttpCalloutMock Test class Failing

I have a Class using MetadataService and different methods of it. I want to create a test class for the same but it is giving an error that my test class have HTTP callouts. I am using the ...
2
votes
1answer
36 views

Regarding Apex Class q1

How do you declare a static method inside with another static method? Is it possible? Why are test class methods always static? Can anyone guide me?
2
votes
4answers
2k views

Class coverage is 0%

I am moving my classes from Sandbox to Production. All the classes have a minimum coverage of 80% in my sandbox. The change set contains both my Apex class and the test class. But in my production, I'...
17
votes
2answers
1k views

Test.setCreatedDate fails on note record created in test context

I'm trying to get a number of records inserted into the database sometime in the past, to allow for a cleanup batch to have proper test coverage. I can use Test.setCreatedDate on the account I'm ...
3
votes
2answers
216 views

What's the uncommitted work on this callout test?

I'm gettin You have uncommitted work pending. Please commit or rollback before calling out.. Exception while Running a Test of the class i will attach. This class is invoked by onTask Trigger (...
-1
votes
1answer
62 views

test method is failing 0% coverage is coming

Controller: public class WizardClass { public Opportunity Oppo{get;set;} public List<Quote> quoteList{get;set;} public List<QuoteLineItem> quoteLineItemList{get;set;} ...
0
votes
2answers
57 views

Testmethod problem: System.QueryException: List has no rows for assignment to SObject

I have the following method in which SOAP webservice is consumed created by wsdl2apex (only necessary part is shown): public class SendOrder { public void SendOrder(string OrderId) { // ...
-1
votes
1answer
496 views

Test Class - System.QueryException: List has no rows for assignment to SObject

I am getting an error System.QueryException: List has no rows for assignment to SObject Class.WebtoLeadScheduledProcess.sendMailDistribution: line 19, column 1 Class.WebtoLeadScheduledProcessTest....
6
votes
3answers
1k views

Testing scheduled apex: CronTrigger does NOT fire after Test.stopTest()

EDIT for clarification of title: CronTrigger is probably actually firing at some point in the testing process - what is wierd is that CronTrigger.TimesTriggered is NOT incrementing after Test....
1
vote
3answers
87 views

Test Method is failing

Controller : public class WizardClass { public Opportunity Oppo{get;set;} public List<Quote> quoteList{get;set;} public WizardClass() { Oppo = new ...
1
vote
1answer
277 views

Test Class for HTTP Callout failing

This may sound repititve question. But the error incurs after following multiple links found like: here and here. The controller: public with sharing class SFLoginCtrlr { public static ...
3
votes
2answers
1k views

Case assignment rule is always executed in the test class

No matter what to do, the case is always assigned by the assignment rule!! You can try the scenario and code which are attached in the post. But, I have tried to execute the code in the developer ...
0
votes
1answer
72 views

Help with Test Class: System.NullPointerException: Attempt to de-reference a null object

My apex consists of an trigger and an apex class. My test class continues to fail with System.NullPointerException: Attempt to de-reference a null object Trigger: trigger PQ_Update on ProdQueue__c (...
-12
votes
2answers
170 views

system.asserts method for test class [closed]

@isTest private static void coverGeneratedCodeCRUDOperations() { // Null Web Service mock implementation System.Test.setMock(WebServiceMock.class, new WebServiceMockImpl()); ...
3
votes
1answer
293 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 ...
3
votes
2answers
7k views

Logged in User in Test class

My apex class extracts all the data of a logged in user for an object. how do I replicate this in my Test class. How do I use System.runAs(User)? The test class is running as me when I say in my code ...
5
votes
0answers
767 views

Process Builder causes Apex Class Test Failure - Stops Migration

My searching for this only displayed a solution which wasn't relevant: Process Builder and Test Classes Use Case: We have a process that creates a chatter post on user record insert OR profile edit. ...
2
votes
1answer
150 views

Testing Batch Class that triggers Chatter Post

I have a batch class that needs a test class. In creating the test records, the insertion of a necessary object record triggers a Chatter Post via another trigger. That chatter post references a ...
1
vote
1answer
699 views

System.AssertException: Assertion Failed: Expected: SQL, Actual: null [closed]

I have the following test class LeadTriggerTest which fails with the following error: System.AssertException: Assertion Failed: Expected: SQL, Actual: null Class.LeadTriggerTest....
3
votes
0answers
625 views

Reference field returning NULL in Test class only

We are facing a very strange issue when writing proper unit test using asserts. We have two objects which have logical link with a field. So, we wrote a batch class to relate those two objects using ...
4
votes
1answer
2k views

Process Builder - Failing test classes

I've written a flow in process builder which references an Apex class with @invocable method. I've written a test class for the same and it's passing as well. Now the problem is all the other test ...
1
vote
0answers
47 views

Test method failure - expecting a DML error but not getting one

I have a test method that is failing because it is expecting an error, but isn't getting one. Here's the test method: static testMethod void assignToSelf_DmlError() { setup(); Test.startTest(...
3
votes
1answer
141 views

Test class completes successfully in production AND newly refreshed sandbox, but fails on deployment

We have some custom code from before I joined the company that is showing some unusual behavior. Code was somehow successfully deployed to production (before my time), and the test code passes within ...
0
votes
1answer
38 views

My method is failing in test

List<Contract> contracts = new List<Contract> { new Contract( AccountId = DB.getAccountByNUID('800000004').Id, Academic_Year__c = '2020-2022', ...
3
votes
1answer
940 views

Hierarchy Custom Setting Test Class Issue

I'm using a Hierarchy Custom Setting field in a validation rule but want my trigger to be able to override the validation rule whenever it runs. I have modified my trigger/helper class to set my ...
0
votes
1answer
518 views

Unable to cover to test class for below trigger

I have written trigger and a test class for my content version Handler public class handlerClassContentVersion{ public set<string>prodNames = new set<string>(); public set<...
1
vote
1answer
253 views

Need Help Optimizing SOQL Query For 100,000+-Record Table (old query, suddenly failing)

Although my org seems to have had over 100,000 Task records for quite some time (as of this morning, we're at 119,479), between a week ago and yesterday two of the test methods that come with an ...
1
vote
1answer
103 views

How to achieve 75% code coverage

When I checked below code in my dev. org. It was almost cover 97% code coverage but when I applied same code in my sandbox it was showing only 10% of code coverage. Strange! Please find below batch ...
-5
votes
1answer
681 views

Compile Error: Arithmetic expressions are not allowed on void types. at line 36 column 26 [closed]

@isTest private class Testcontactcloud{ static testMethod void unitTest(){ Test.StartTest(); contactcloudcontroller objccc=new contactcloudcontroller(); ...
0
votes
1answer
43 views

Company names list configuration test method

I have the following method public static String splitCompanyName(String company) { String companyNameLowerCase = company.toLowerCase(); // get all extensions from the salesforce list and are ...
0
votes
1answer
3k views

How to cover pagereference method in test class

I have a method like page reference method in my class. How to cover the pagereference method in test class??? all the other methods were covered except the pagereference method. I tried like: ...
0
votes
0answers
139 views

System.Null pointer exception error on an empty line of code?

I am getting below error in a test class when I want to save another class. System.NullPointerException: Attempt to de-reference a null object at line 32 The problem is that I commented line 32, but ...
3
votes
1answer
1k views

Query works in Anonymous Window but fails in Test Class

I am new to APEX and ask forgiveness if the answer to my question is obvious, but I can't find a reason for the action that occurs in the Test class versus production and the Developer Console ...
1
vote
2answers
52 views

Apex Test issues creating a quote - page error missing or inactive pricing type/pricebook

I am trying to update some older test code to remove seeallData=true. I am getting a page error testing a quote controller extension that creates a new quote. System.AssertException: Assertion ...
0
votes
1answer
52 views

How to properly create and use test data for test classes?

So I've had gained a lot of experience coding apex classes and Visualforce pages but there is still one concept that is really causing frustration for me and that is how to write proper test classes. ...
0
votes
1answer
46 views

Need help in test class for code coverage

I have a requirement, where i need to populate all the related contacts in Account Object Detail Page with comma seperated. For Example : If I have Account1 and Contact1 and Contact2 are related to ...