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
-1
votes
0answers
22 views

I need to increase code coverage, I have 33% and I am getting no code coverage for the Contact SOQL

public class UpdateContactfieldsonthebill{ public static String getAccount(loan__Loan_account_Due_Details__c a) { Account a1 = [SELECT Id, Name, CurrencyIsoCode FROM Account WHERE Name =: ...
0
votes
0answers
22 views

Can someone help me how to write Test Class [duplicate]

I just want to know how to write Test Code.. I've no Idea About it. If Someone can Explain me what are the keypoints to write a Test Class I've also tried to write Test Class. In this Test Class It is ...
0
votes
1answer
23 views

Test Class for Contact [duplicate]

I have a code that is testing a batch, I am creating a contact and an Account , but the contact isn't getting linked to the account (c.AccountId = null). The same code is tested in Async window and it ...
-1
votes
1answer
31 views

How to write a test for a VisualEditor.DynamicPickList class?

I have this DynamicPickList class that creates picklist values based on what lookups have been put on the Contact object. It is used in the targetConfigs of a LWC. How do I write a test for this class?...
4
votes
1answer
42 views

How to mock App Exchange package's API response?

I am using an app exchange package in my code, they have exposed a few global methods that I can use to get my job done. It all works beautifully. The issue comes with testing. I want to test ...
-2
votes
0answers
16 views

Test Class for the following class [duplicate]

public class QuoteIndiaPDF_Controller { public string quoteIdVal; public List<QuoteLineItem> quoteLineItemList{get;set;} public List<Terms_and_Conditions__c> cusList{get;set;} ...
0
votes
0answers
28 views

i am unable to write test class for following Controller of select list and select option.Please suggest [duplicate]

public class TemplateController{ Public Id accId{get;set;} Public String SelectedTemplate {get;set;} Public Agreement_Template_Settings__c newCS{get;set;} public TemplateController(...
-2
votes
0answers
24 views

I have written the test class for apex and it gives code coverage only 50% . Can any one help to complete minimum 80%. Thanks in advance [duplicate]

Apex class: public static void listMethod(){ List <Case> caseList = new List<Case>(); try{ caseList=[SELECT Id, Email_Reply__c,(SELECT createdDate FROM ...
0
votes
2answers
40 views

How to test and assert email template?

I'm getting this error: System.DmlException: Insert failed. First exception on row 0; first error: MIXED_DML_OPERATION, DML operation on setup object is not permitted after you have updated a non-...
-3
votes
1answer
40 views

Test class not sure how to write for this code [duplicate]

I have written following apex class: public with sharing class Persmissionset { @AuraEnabled public static PermissionPagerWrapper fetchPermission(Decimal pageNumber ,Integer recordToDisply) { ...
0
votes
1answer
22 views

Issues with this Test Class for this Opportunity Trigger

I have created a trigger that on clicking the Sync Quote button it will update Opportunity Products with custom fields our organization needs to put into the accounting system trigger ...
1
vote
1answer
28 views

Unit Test - Flow Variable to Apex Class to HttpRequest

For context, I am usually just a declarative Admin and can usually achieve whatever I need to on the platform using Flow, PB, or simple WFR. Very seldom do I have to 'resort' to Apex. I have a Flow ...
-2
votes
3answers
51 views

Attempt to de-reference a null object - error in test class

I am trying to update business unit field in business_unit__c custom object. for this we have used custom settings in trigger and if manually any sales rep is creating based on their role we created a ...
1
vote
1answer
19 views

Apex Batch Test Class for Opps with OLIs not returning values

I'm struggling with an Test Class for a little batch I created, let me clarify that I'm not a developer, so any tips will be appreciated. I wrote 2 versions of the class, the first gives me about 94% ...
1
vote
0answers
32 views

Testing Batchable with Callout Error: You have uncommitted work pending. Please commit or rollback before calling out [duplicate]

I have a Batchable class which does a callout. When I test the class which like this: Test.startTest() MyBatchableJob job = new MyBatchableJob(); Database.executeBatch(job, 50); Test.stopTest(); I ...
2
votes
1answer
109 views

Where or how can I find what interfaces an out of the box Apex class implements?

Is there a method of discovering (or a place to look up) all of the interfaces that an out of the box Salesforce class (Like LoginHistory) implements? The reason I ask: I'm attempting to test a ...
1
vote
1answer
38 views

Wrapper in return method for test class

I'm creating a visualforce page for a Dashboard component. In the controller I have a wrapper class and in one of the methods I return a map of a list of the wrapper records. Example trimmed down: ...
-3
votes
1answer
36 views

Use of @testSetup method in a Batch Class [closed]

I have created a @testSetup method to create a data which generic. In my test method I am querying the data for some specific records and calling my batch class. The batch class is taking all the ...
0
votes
0answers
14 views

How to get covered my aggregate result in my test class [duplicate]

I have one class and in my test class i am getting only 65 % code coverage, and all my aggregate function is red. How could I cover these lines of code? Here is my class global class ...
0
votes
1answer
28 views

FATAL_ERROR System.JSONException: Malformed JSON: Expected '{' at the beginning of object

I am trying to test a REST API call, but getting FATAL_ERROR System.JSONException: Malformed JSON: Expected '{' at the beginning of object. Why do I get this error? How do I resolve it? Here is ...
0
votes
1answer
29 views

how to make a test so that the lead owner is the same as the contact owner

I'm starting to learn apex and I need to write a test for a simple trigger so I can have 100% code coverage. Here's my trigger: trigger UpdatePropietario on Lead (after update) { Id pId; for(...
1
vote
2answers
28 views

Apex Test class for web-to-lead creation without OwnerId

I need to create an Apex test class for a Lead Apex Trigger that handles "before insert" of the web-to-lead inserts of Lead records that DON'T have OwnerId at the "before insert" time. Assigning of ...
-1
votes
1answer
48 views

Test for SOQL in Apex Controller

I'm not sure if I'm testing correctly. What check here should be done? Could you help with the test? public class Controller { public List<MyTool__c> tools {get;set;} public Controller(...
1
vote
0answers
25 views

Test Class for Approval Process - Problem with ProcessInstanceWorkItem

I'm starting with code and test classes. I have a class that reject an approval process for an account. I start this class by a process builder. This is the code: public class ...
0
votes
0answers
15 views

Test batch with multiples Callouts - HTTPMock [duplicate]

I have a Class that integrate Api , there are many Callouts in there. And I have a Batch Class that running on functions of this class. My question is about the test class. test class: @...
0
votes
2answers
20 views

SOSL not returning record in test

I have EditorModalController.searchDoctors that returns a list of contacts. public class EditorModalController { @AuraEnabled public static List<Contact> searchDoctors(String ...
1
vote
0answers
26 views

Help writing Salefsorce Api call Test class

I have used some of the guides available like (https://developer.salesforce.com/docs/atlas.en-us.apexcode.meta/apexcode/apex_classes_restful_http_testing_httpcalloutmock.htm), but still having trouble ...
0
votes
2answers
40 views

Problems with testing the population of duplicate information from DuplicateRecordItem on Account record

I have created three fields on Account to store information on the duplicates in the system. Standard duplicate rules apply. The fields are: Duplikat__c: a checkbox ID_Doppelte_Datensaetze__c: Id ...
0
votes
3answers
40 views

How can I get test coverage for a Visualforce controller?

with this test class I have a coverage of 0% someone has an idea why it does not work I can not recover the id of the product it seems that it is not inserted public with sharing class ...
0
votes
2answers
35 views

Test Class is sucssess in Sandbox but failed on deployment

I want to know, what can cause a test class to run in a sandbox and PASS all the tests, but on deployment to another sandbox, its failed during the deployment? all of my data is created in the test ...
1
vote
2answers
32 views

How to split the n test cases of one method among n methods?

I have created a method where I test a trigger and I do something like this: method(){ insert row1 assertequals... insert row2 assertequals... insert row3 assertequals... ... } So that I have n ...
0
votes
0answers
18 views

class test for controller [duplicate]

I need some assistance writing a test class for this extension controller : public with sharing class ControllerOppRel { public Product2 opptyList; public ControllerOppRel (ApexPages....
0
votes
2answers
303 views

runAs() behavior in prod vs sandbox

Recently we came across this strange behavior in prod vs sandbox deployment. As part of mock deployment, we deployed the exact same class(es) to a recently created sandbox and everything was fine. Now,...
0
votes
0answers
9 views

How come my enqueued class is still getting executed in my unit test when I never call start/stopTest methods? [duplicate]

Per salesforce docs (https://developer.salesforce.com/docs/atlas.en-us.apexcode.meta/apexcode/apex_testing_tools_start_stop_test.htm): All asynchronous calls made after the startTest method are ...
0
votes
1answer
41 views

Why are field updates inside an Apex trigger not showing up in an Apex test?

I have a very strange issue with some Apex tests for a trigger. The tests each check a different type of field update; when one field is changed, the trigger is supposed to change another field. On a ...
0
votes
2answers
25 views

How to get pagestate rolodexState in unittest with corresponding ids's

I have a button on the contact list pagelayout. The functionality of the button is to select multiple records and pass the ids to a visualforce page to start a flow through url. When creating a ...
2
votes
1answer
56 views

Opportunity close date is not being set to today when closed while close date is in the future

We are implementing an override of the close date functionality. By default, opportunities that are closed and have a close date set to the future get their close date set to today. We want this to ...
0
votes
0answers
33 views

Hi, Iam new to salesforce, cant able to write test class for below code [duplicate]

public class countthecontacts { public void insertcontact(){ list<Account> acclist = new list<Account>(); list<contact> conlist = new list<contact>(); ...
0
votes
1answer
38 views

Schedulable error: You have uncommitted work pending. Please commit or rollback before calling out

I am trying to test Schedulable class which is designed to only run once. Because it's only runs once, I need to test that the System.abortJob is working correctly. I am using this code to test: ...
3
votes
2answers
93 views

How to test CRUD and FLS in unit tests?

BACKGROUND I am working on a managed package and it contains a custom object (X__c) with one custom field (X__c.Fld__c). In the controller I check if a user has Read access to both the object and ...
0
votes
2answers
37 views

IntelliJ not showing code coverage for class

I'm having trouble with identifying code coverage in IntelliJ for my Apex class. On the side of my project, after activating "Run with Coverage," the percentage of lines covered is shown: But the ...
0
votes
1answer
15 views

Does change set validation run tests within the change set or those already in the org?

When you deploy an inbound change set with apex classes and their respective test classes in the change set, does the validation run tests that are in the change set or those already in the org? So ...
0
votes
1answer
22 views

DUPLICATE_VALUE, This price definition already exists in this price book: [] while deploying to production

please see starred(***) part in both method, I am getting error while deploying in production not in sandbox @isTest public class DuplicateProduct_Test { public static testMethod void callMeth() ...
2
votes
1answer
65 views

Run Single Test for Lightning Web Component

I feel like this is a stupid question, but I can't find the answer anywhere. Is there a way to run a single test file for a single Lightning Web Component. I essentially want to be able to pass ...
4
votes
1answer
47 views

Testing an approval process - should I create metadata just to test?

I have an Apex test that is testing if a record is in an approval process. To test, I have to submit a record for approval - but there is no guarantee that there will be an approval process set up in ...
0
votes
1answer
25 views

FIELD_INTEGRITY_EXCEPTION, field integrity exception: unknown (scheduling not enabled on product): [unknown]

I am setting up some test data for my unit test but am hitting the wall when inserting a OpportunityLineItemSchedule. Here's my code: @IsTest static void myTest() { Account acct = new Account();...
2
votes
2answers
19 views

Which unit tests should check read access for user?

We are using fflib-apex-common in our project, and we implemented several selectors. By default fflib_SObjectSelector checks for Read permission. But now I am wondering what type of tests, and at what ...
1
vote
1answer
25 views

Testing bulk clone operation

After doing enough Google search and scratching my brain, I have decided to post here and seek for suggestions. Here is the background: An opportunity has multiple order & order line item ...
2
votes
2answers
70 views

ContentVersion FileExtension

Does anyone know how I can change the FileExtension for a new ContentVersion in a test class? Im currently trying to create a test class for my ContentDocumentLink Trigger, in which I have an if ...
1
vote
1answer
99 views

FIELD_INTEGRITY_EXCEPTION, Invalid role assignment.: []

I am building some test data in my unit test. Roughly I have something like this: @IsTest static void getUserTest() { Account acct = new Account(); acct.Name = 'Test Account'; insert ...