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
2answers
36 views

Test Class with No Input [closed]

This is my Controller: And this is my test class: and this is the error I'm receiving:
-3
votes
0answers
24 views

Need help for writing test class of callout. New to integration [closed]

System.UnexpectedException: Script-thrown exception Class.PegaCallbackService.RequestAuthorizationToken: line 29, column 1 Class.PegaCallbackService.SendValidationStatus: line 46, column 1 public ...
0
votes
0answers
17 views

Assistance with Test Class [duplicate]

I could get a sample class to automatically deactivate inactive users in Salesforce and did some changes to it: public class DeactivateInactiveUsers implements Schedulable { public void ...
0
votes
1answer
19 views

Illegal assignment from Boolean to Casecomments__c

Please help me to get the test class for below class. public inherited sharing class BI_QuickCloseCompController { private static final String CLASS_NAME='BI_QuickCloseCompController'; ...
1
vote
2answers
49 views

How to correctly construct a TestClass for an API Rest Callout | Getting the error “Method does not exist or incorrect signature”

Apex Class for REST Callout public with sharing class FindAnApprenticeship { public class Payload{ @invocableVariable(label='Find An Apprenticeship URL') public String ...
0
votes
3answers
32 views

Setting a Map value within a method for a unit test

I still learning here but I am having a bit of trouble understanding this concept. I have a method kind of like this: public static List<Contact> newContacts() { List<Contact> ...
0
votes
0answers
17 views

Approval process test class unanimous approval required

I have a trigger that grabs approval comments and updates a custom field on an opportunity record. I am able to get 100% code coverage on test class when approval process requires one approver. ...
0
votes
1answer
62 views

Site.forgotPassword() Failing In Test Class - Code Coverage Not Reached

I am trying to successfully run Site.forgotPassword() in a test class, but the method is returning False when used in my test class. I have tried using real Users (as demonstrated in the code below), ...
-3
votes
0answers
22 views

this is my apex class help me to write test class for this,thanks in advance [duplicate]

public static decimal Httpmethod(decimal USD) { Http http1 = new Http(); HttpRequest req1 = new HttpRequest(); req1.setendpoint('https://api.exchangeratesapi.io/latest?base=USD'); ...
2
votes
0answers
34 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 ...
0
votes
0answers
31 views

JSON mocking fails with Internal Salesforce Error when working with ChangeEvent records

Most of the time I write my test classes using JSON mocking and I am trying to follow the same for class that works with AccountChangeEvent but it is failing with error Internal Salesforce Error. I ...
1
vote
0answers
33 views

How to delete a Person Account in Apex Test

I have difficulty to delete Person Account(PA) in Apex test. The reason is that I cannot figure out how to disable the associated user record. The org has Salesforce SSO and PA feature enabled. Here ...
-2
votes
0answers
46 views

Facing 101 soql exception in case of testing batch class

I am facing error of 101 soql in case of running test class for batch class. Please find the batch class and test class as below: Batch Class: /******************************************************...
0
votes
2answers
31 views

How to write a test list of the Trigger [duplicate]

I am very new at the development. I finish writing the Trigger but have no idea with the test code. I trying to write the test code but get 0% of code coverage. Here is my Trigger and test code. ...
0
votes
2answers
45 views

Trigger and its test class

I am new to Salesforce. I have written a trigger to update contact based on account field. The Trigger code is below. trigger Update_contact_based_on_acc on Account (before update) { List<...
0
votes
1answer
40 views

CSV file string parsing by newline error

I'm trying to write unit tests. The unit tests have input of a stringed csv file. So I'm having csvFileDataAsString as the simulated input. String csvFileDataAsString = 'Column1,Column2,Column3\...
0
votes
1answer
30 views

Test method does not cover line even though it's populated

I'm working on a test method for a trigger that I wrote that when a user is deactivated it sends an email to the manager. My problem is that in my test I populate the ManagerId field but the test ...
1
vote
1answer
37 views

Add more than 200 test classes in the test suite

I am trying to add test classes in the test suite. But when I click on save, I am getting below error: I am trying to add more test classes using Apex like below using Anonymous execution: List<...
1
vote
2answers
63 views

Geting 88% code coverage while running test class but while deploying it in production it is giving 63% code coverage

I am getting 88% code coverage when I run the test class but when I am deploying it in production it is giving 63% code coverage Below is the apex class code public class ...
3
votes
2answers
110 views

How to use Stub API in the following scenario?

I am trying to understand Stub API a bit: My Class: public class DistributedMSelector { public static Map<string, user> getUserMap(Set<String> employeeIdSet){ Map<String,...
5
votes
1answer
55 views

Why are my matchers not working after adding an overloaded method?

To help getting past our permission checks during unit tests to test actual functionality, I created a mocking class so people could just call the mocking method they needed from that class for the ...
4
votes
0answers
44 views

Can we work around Owner related fields not being retrievable via SOQL in apex tests?

Background: Recently I wrote a very simple Batch to run on the 1st of every month. Its purpose is to query for any Project__c records that aren't Complete, and create a related "Carry-Over" record in ...
0
votes
2answers
41 views

do not run process builder from test class execution [duplicate]

we have one test class on execution process builder is getting fired. is there any way where I can avoid to run process builder while running test class.
1
vote
0answers
40 views

Issue with test class coverage

@isTest public class SchedulableStartVendorCases_Test { @testSetup static void setup() { Account acct = TestUtil.getLegalEntityAccount(); insert acct; DateTime ...
1
vote
1answer
46 views

Testing a method that uses the Box Salesforce Developer Toolkit sendRequest generic method

Wanted to see if anyone has encountered/solved this issue. We have the Box.com app installed in Salesforce (Lightning, Enterprise edition) and I’ve written a function that makes a call to the Box....
-2
votes
1answer
27 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: ...
-2
votes
2answers
54 views

System.NullPointerException: Attempt to de-reference a null object error in test class

I am getting null pointer exception while creating a test class for schedule apex static testMethod void testMethod2(){ test.startTest(); Settings__cPS = new ...
2
votes
1answer
32 views

Does Test.testSandboxPostCopyScript Actually Run DML?

I have a SandboxPostCopy class where I am updating some User fields (example: changing the email to remove the '.invalid' and setting Profiles) where the Users to be updated are controlled by Custom ...
1
vote
2answers
41 views

Organization lock while running apex test class

When I run any test class other developers see issue like below while saving classes in the developer console: The changes you requested require salesforce.com to temporarily lock your organization's ...
1
vote
1answer
24 views

Setup method System.QueryException: List has no rows for assignment to SObject

Can someone help me out with my test class, Im getting an error where it says list has no rows? @isTest private class dailyUpdatesMortgageTest{ @testSetup static void setup(){ //...
0
votes
1answer
21 views

How do I test a schedulable email sending?

I have a schedulable apex class for the email sending. I tested a schedule, but I can't to coverage sending logic. Is there a some way to test good and bad scenarios for it? My class: public class ...
-3
votes
1answer
24 views

Need help Schedule Test Class for tast create on Opportunity

I need help on the test class for this schedule on Opportunity. Getting error on below code with comment and only 35% coverage code. global class OppJob_Task_1stPhoneFollowup implements Schedulable { ...
0
votes
1answer
26 views

REST API GET Callout and test method

I have created a class Apex class to get info from and external database and insert the info to the account before save. The method is called by a trigger. Everything is working fine but I am getting ...
2
votes
1answer
25 views

Is there any way to mock and test Salesforce Streaming?

Is there any way to mock and test Salesforce Streaming? How do you test Salesforce Streaming API ?
0
votes
0answers
28 views

Unit Test is Providing 0% Coverage for Apex Trigger - Test class for trigger [duplicate]

trigger Splittrigger_newclass on Indexing__c (before delete,after insert) { list<C_Voyage__c> lstvoyage=new list<C_Voyage__c>(); list<string> q = new list<string>(); ...
1
vote
2answers
31 views

Methods defined as TestMethod do not support Web service callouts on working test class [closed]

I'm experiencing a wierd thing, I'm made a deployment on a refactoring of code on cases this monday (2019.12.02) and my test classes use the Test.setMock method. It worked so I started doing the same ...
1
vote
0answers
23 views

Bulk testing being restricted by limitation with Database.batchExecute() - How to overcome?

I was getting an occasional UNABLE_TO_LOCK_ROW error when two records were saved very close to each other. Related records were getting locked by one trigger invocation, and a second trigger ...
1
vote
1answer
125 views

LWC: unit testing component using validity object

I have an lwc component which validates some input fields before performing a post request to the server. I'm writing a unit test where I'm testing that the post request is called when all input ...
3
votes
4answers
90 views

Shall I disable triggers in testing data setup phase?

I tend to create unit tests more than integration tests in Apex. When creating unit tests, one step is to prepare data (insert/update). In this step, shall I disable trigger logics (assuming a ...
0
votes
1answer
25 views

Why salesforce doesnt provide testing environment for Callouts?

We can only test classes with mock callouts but cannot do a callout directly from a test class. (If we do test class fails). Is there a reason?
-2
votes
1answer
22 views

Salesforce Messaging.SingleEmailMessage Test Class

Can anyone help me get test coverage for Messaging.SingleEmailMessage? I'm using email template. Whenever a Case closes, it should send email to Contact.Email and bcc emails of the custom label. How ...
1
vote
0answers
44 views

Need Test Classes for AutocreatedConfigSelfReg and AutocreatedDiscLoginHandler

I'm an admin and beginner developer who was setting up a community and thought that the login discovery page was a great user experience. Without due-diligence, I went ahead and selected the "create a ...
0
votes
0answers
20 views

How to write a test class for the below mentioned trigger (code) [duplicate]

trigger IdentialContact on Account (after insert) { List<contact> cont = new List<contact>(); for (Account acct : Trigger.new) { for (integer i=0 ; i<2 ; i++) { ...
0
votes
2answers
60 views

Getting CANNOT_INSERT_UPDATE_ACTIVATE_ENTITY error when testing Apex

I'm re-writing unit tests for the Apex Specialist superbadge (yes, re-writing, I successfully completed the superbadge a couple of days ago, and found a few bugs while playing around today, decided to ...
0
votes
0answers
29 views

How to do positive and Negative test for my test class for the below code [duplicate]

Need some advice on test classes, i dont know how to perform positive or negative tests on my test classes, Any advice would be highly appreciated below is my apex code for visualfore controller ...
3
votes
1answer
50 views

Why can't I Insert ContentDocumentLink linking to Community user?

I have written a trigger class on content document link to create a task whenever a community user creates a task on a case. Currently, the trigger works perfectly when attaching a case through the UI,...
0
votes
2answers
35 views

Access from Test class to Inner class

I tried to test my method which is using inner class. Wrote like this, and got error Invalid type: innerclass. Apex public class myclass { public class innerclass { @AuraEnabled ...
0
votes
2answers
34 views

Why is associated User information null when queried through a lookup in a test?

I have an apex class that I am testing that queries for the record Owner information on leads. When I try to access the Owner information the values are null. However, when I query the user object ...
0
votes
0answers
38 views

Test Class Coverage: unable to associate Territory data with Group and AccountShare Objects

While writing test class, I am unable create the data that connects AccountShare, Group and Territory. Group and Territory are related by the field relatedID on Group which is read only. Has anybody ...
0
votes
3answers
82 views

Trigger, after first soql seems to stop executing without error. *Edit*

*EDIT-I have updated my code with more explanation and debugs showing what is printed and where execution unexpectedly exits without error. I am also only working with 1 test method for now. I am ...