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
1
vote
1answer
215 views

How can I test Post Callout with web token's access? HttpCalloutMock

My POST Method (data for web token - is my custom object's fields): public class Token{ public String accessToken{get;set;} } public static String accessTokenBody(){ //our web token (data is in ...
0
votes
1answer
172 views

How to test access token for HTTP callouts?

I have an access token for my HTTP callouts. How can I test it if I wanna use Static Resource? But I can also use the HttpCalloutMock Interface. it doesn't matter My access token is in custom object. ...
1
vote
1answer
108 views

How can I test Callouts with HttpCalloutMock?

How can I test this method? I try the test code from trailhead but can't make any coverage. Callout: public class Token{ public String accessToken{get;set;} } public static HttpResponse ...
0
votes
1answer
54 views

Correct HttpPatch and correct test for it

I need to update a right record with ExternalID = Id of inserted record. And I try to check this field (ExternalID) in SOQL, but get an error System.QueryException: List has no rows for assignment to ...
1
vote
2answers
163 views

setting RecordType in Test Coverage

I am having trouble on a test that is setting a record type. I believe I am setting the record type the correct way, the test is passing, but my test coverage is telling me that no record type was set....
0
votes
1answer
195 views

Social Sign On for Salesforce Reg Handler Class and Test Class-System.NullPointerException: Attempt to de-reference a null object

My org is setting up social sign on with Google and I am running into an error I have never seen before: System.NullPointerException: Attempt to de-reference a null object Does anyone know a ...
1
vote
1answer
32 views

What kind of test can I write to check the file?

I have a controller for VF Page. This code upload a profile's image (we can see it after that) and delete it. What kind of test can help me to check this file? I need to know, is it uploaded or not. ...
0
votes
1answer
178 views

Static method cannot be referenced from a non static context (PageReference)

What is wrong here? Candidate__c cand = new Candidate__c(); insert cand; PageReference pageRef = Page.UploadCandidatePhotoVF; Test.startTest(); Test.setCurrentPage(pageRef); ...
0
votes
2answers
109 views

Make the test work: File insert, check this File

This code is a controller for my VF Page. It inserts ContentVersion and ContentDocumentLink. After that a candidate field Photo__c take a ContentVersion.Id value. How to check it correctly? Now ...
0
votes
1answer
42 views

Trigger Test fails because check for roll-up field value in Trigger finds old value

I have a trigger on a custom object, Subscription__c, (child of Account) which is supposed to give the Account TelemarketingPrioritizedFor__c = 'Winback' if, and only if, the field ...
1
vote
0answers
30 views

Unaltered Test passes in Sandbox AND Production, but fails during unrelated deployment validation

I am trying to deploy a few classes. I've got a Sandbox that I literally created this morning off of Production. Nothing is different between the two except the 3 classes I'm deploying. How can it ...
4
votes
1answer
106 views

Why won't Apex IF statement work in Production Unit Testing after working in sandbox?

this is driving me NUTS and any thoughts are MUCH appreciated after looking at this for far too long. Use case: users in certain profiles need to be automatically added/removed from a particular ...
1
vote
1answer
31 views

How to test a change OwnerId by groupQueue.Id?

I have a trigger. If a user who creates a record isn't 'Manager' (UserRole.Name) - record's OwnerId change to GroupQueue.Id. I have a correct test method for scenario, where user-creator is 'Manager', ...
0
votes
2answers
30 views

Test Coverage Help - Insert Custom Object But No Test Coverage

Hopefully this will be an easy one and I am just missing something small. I have a method queries for a custom object. My test class isn't seeing the custom object I have created in the test class. ...
0
votes
1answer
27 views

Trigger Test Class failing assertion

For the following class, I have a test class with two methods. The second method is failing at System.assert(Jet2.Status__c == 'Booked'). The status is still 'Active.' How do I fix this? Trigger ...
4
votes
1answer
2k views

What should the negative tests include?

While preparing myself to the Developer 1 certification I met the following question: A developer is asked to write negative tests as part of the unit testing for a method that calculates a person's ...
0
votes
1answer
336 views

assertEquals | All Object Properties Are the Same but the Assertion Fails

In my tests I create an object and compare it to the one returned in the function using System.assertEquals. Despite all the properties being exactly the same I still get the "Assertion Failed" ...
1
vote
1answer
31 views

Case Number duplicates found for case insert in Test Class

I faced a weird scenario today. I have a @testSetup method for inserting my case records and then used another method to query those case records to fetch CaseNumber field and pass it to a JSON String ...
0
votes
1answer
377 views

How to cover the below lines in my test class code coverage?

Can someone please help me how can I get the code coverage for below line: Test class code: @istest public class Testownerassisgnbasedonaccount { @isTest static void ...
4
votes
2answers
1k views

How do I create Test Data for an Org. Wide Email Address?

I need to create an Org. Wide Email address for my Test Class, and I can't seem to find documentation for this. One forum led me to believe it wasn't possible, but it wasn't clear if I was ...
-3
votes
1answer
53 views

Test class failing for striphtml method

I need some help with test class which is failing.Here is my code trigger striptext on customobj__c (before insert, before update) { for customobj__c atxt:trigger.new) { if (atxt.Record_Type_Name__c ...
1
vote
4answers
80 views

No Code Coverage

I am working on an Org with some old code that is beyond my admin / learing Apex ability to fix. This trigger is throwing errors for two many future calls and it no long serves any purpose in our Org. ...
0
votes
1answer
57 views

How can I get code coverage for a constructor method in a StandardSet controller?

I am struggling hard to get code coverage for following constructor method with some URL method usage. Basically the filter name I am trying to fetch is the list view ID (also need some insights to ...
0
votes
1answer
52 views

Test Coverage for Current Page Id

not sure what I am doing wrong here with setting the page id in the test class. Can anyone see what I am doing wrong? The failed test is throwing System.NullPointerException: Argument 1 cannot be null ...
0
votes
1answer
98 views

Test failure 7% for HTTP Call out [closed]

I am not sure why I am getting the two errors I labeled below during the http send in the first class or in the Mock Impl class when I assert the endpoint. public class ProcessHandlerShowAccounts { ...
2
votes
2answers
271 views

Field appearing NULL in tests

I have a helper class that is working as intended while testing manually but in tests it is failing. I am trying to test the following method: public class helper { @TestVisible private ...
2
votes
1answer
2k views

regarding External entry point

i have one custom field called Unique_Vendor_Id__c on account object (external id checkbox checked) and its auto-number. now in test class when i create account for test data Unique_Vendor_Id__c ...
1
vote
1answer
599 views

Empty picklist value is getting saved as null

I am trying test a piece of code by changing a Status__c field on Save_Attempt__c Object. I am explicitly setting the value of Status picklist to an empty string and not null but when I query, it's ...
3
votes
2answers
990 views

Platform Event Testing: Unexpected Exception: Error processing messages

I've been doing a lot of work with Platform events and found it a fantastic way to implement some domain driven design patterns, decouple code, and separate execution contexts. Unfortunately I've been ...
0
votes
2answers
1k views

Test class coverage for custom label

I have the following code where the intent is to log the details of the object only when the value of the custom label is true. This way I can control enabling logs from custom label settings. I do ...
0
votes
2answers
86 views

Unable to cover few lines in Test class

Apex Controller: public class Controller{ @AuraEnabled public static string createTask(String BankID){ List<Bank__c> ls = new List<Bank__c>(); System.debug('>>>'+...
0
votes
2answers
60 views

Attempt to de-reference a null object when traversing DescribeSObjectResult to check permissions

I have this method that checks a user's write permissions on an Apex controller. It works just fine at runtime. However, I'm writing a test to cover it (indirectly) and I'm getting a 'Attempt to de-...
1
vote
1answer
255 views

How to write test cases for Dynamic picklist

I have a dynamic picklist that I am displaying on the visualforce page. Here is my visualforce code: <apex:selectList value="{!SelectedNomination}" size="1" id="a"> <apex:selectOptions ...
0
votes
1answer
110 views

Basic Mock Test Coverage Help

I think this will be a easy fix, I am sure it is something I am just overlooking at the end of the day. I created a mock class to test my callouts. It is called SingleRequestMockClass.cls, I got the ...
-4
votes
1answer
59 views

Apex Test Code Coverage Issue for Aggregate Functions

I have 2 objects Order and Shipment__c. For each Order we can have Multiple shipments and I'm trying to update the Order with MAX(ship Date) from all related shipment records. The trigger and helper ...
0
votes
1answer
41 views

Test Method for Case Insert from Trigger

I have a trigger that fires when an Opportunity is Closed Won, has OpportunityLineItems and those OppLineItems relate to a specific Product. The firing of the trigger creates a Case Record based on ...
0
votes
2answers
74 views

Error with Apex callout

I'm trying to connect to a web portal via API's. HttpRequest httpRequest = new HttpRequest(); httpRequest.setEndpoint('xxxxxxxxxxxxxxxxxxxxxxxx'); String body='account=xxxx&authenticationkey=...
4
votes
0answers
180 views

Intermittent Process Builder Flow Error - How to troubleshoot with no info?

Background I'm getting a dreaded flow error for one of our test methods that occurs fairly regularly, but not consistently. I've reviewed the debug logs thoroughly, but can't see any obvious way to ...
1
vote
1answer
91 views

@HttpPost test will not run - Method does not exist or incorrect signature: void doPost(String,

Just started with Apex last week so very new. Building a @RestResource to pick up webhooks sent from an external DB. Code has been tested and working as expected in Sandbox. Can not get the unit ...
0
votes
1answer
605 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
2answers
329 views

Why is my After Delete Trigger test class failing?

I have a trigger set up on the Account object for After Delete. We have an Affiliates table that has a lookup field to Account. If an Account is merged, I don't want to delete an Affiliate. It will ...
5
votes
1answer
291 views

Is it normal to tests not be able to create queues because there's one with the same name on the organization?

If I have, for example, in production a MyQueue queue, with the same DeveloperName, and I'm trying to run a test class to deploy a change set, which contains a test that inserts a MyQueue queue as ...
0
votes
0answers
120 views

Force calculation of Cross Object formula to be used in test class

The basic gist of my issue is that I have a batch apex class that uses cross object formulas in some IF statements (Something like Contact.Account.FirstName). The problem is that when I create the ...
6
votes
0answers
137 views

Why inserting a user object and making callout in a test throws CalloutException in Production?

I stumbled upon strange behavior when executing tests on deployment to production organization. In the test, I first insert a User object, some other objects and then as the last one, a CampaignMember ...
2
votes
1answer
36 views

Custom Object Relationship query behaves differently in Test from Execute Anonymous

Background I have a custom object Contact_Coverage__c. I have a custom field Contact_Coverage__c added to the Activity standard object, with the child relationship name Activities__r. In general, I ...
0
votes
1answer
36 views

I cannot delete a contact due to “System.NullPointerException: Attempt to de-reference a null object”

I have this trigger: trigger deleteContactReceiver on Contact (before delete) { List<Contact> con=Trigger.new; GDPRContact.deleteContactURN(con); } Invokes: public static void ...
2
votes
2answers
520 views

Sudden MIXED_DML_OPERATION errors without code changes

So I have 3 orgs that are basically all on the same codebase. On the production org (the one that gets changed the least) some of the tests are suddenly failing - all with the same error message: ...
1
vote
0answers
187 views

Apex test classes fail on HTTPResponse

I have some test classes that run decently until they hit something like HTTResponse res = h.send(req); Where I then get 'System.UnexpectedException: Script-thrown exception'. I make a few ...
0
votes
2answers
257 views

Test class error on validation : A flow trigger failed to execute the flow with version ID

I am getting an error when trying to do a validation on a changeset on production. The error that I receive is as below. System.DmlException: Insert failed. First exception on row 0; first error: ...
0
votes
1answer
38 views

production is generating more records in test class, causing failed validation

I created a Lightning Component Controller. It's suppose to clone our custom object pba__Offer__c. In our staging environment, I've managed to get 97% code coverage, and all my asserts pass. Class ...