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
-2
votes
2answers
133 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
26 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
41 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
133 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
284 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
79 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
16 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
113 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
32 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
82 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
62 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
127 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
19 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
97 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
27 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
145 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
46 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
155 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
39 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
330 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
10 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
45 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
26 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
564 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
39 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
68 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
328 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 ...
1
vote
2answers
430 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
95 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
75 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
274 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
58 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
90 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
28 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
70 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
511 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
1k 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 ...
1
vote
0answers
19 views

How to Access Item in a List of SendEmailQuickActionDefaults

I have the following: List<QuickAction.SendEmailQuickActionDefaults> defaultsSettings = (SendEmailQuickActionDefaults:[QuickActionDefaults.actionName=Case.CC_Send_Email, QuickActionDefaults....
1
vote
2answers
50 views

Unable to assert in test for QuickAction.SendEmailQuickActionDefaults

I have a class for setting a default ToAddress when using a specific email action. See below: global class EmailHandler implements QuickAction.QuickActionDefaultsHandler { // Empty constructor ...
0
votes
1answer
67 views

Test pagereference with selection of multiple Ids

I have a visualforce page where I select multiple ids. Based on my selection I start a flow. I dont know how to simulate the selection in my testclass. Visualforce <apex:page standardController="...
1
vote
1answer
300 views

Attempt to de-reference a null object when calling class method from Test class

I am trying to write a test method that calls a method in my class to get some configuration data. The method in my class returns a Map. From my test method, when I call the method in my class, I ...
-4
votes
1answer
87 views

Test class for below class [closed]

public class ExampleClass { public static void publishCaseUpdateNotifications(List<Case> cases) { List<Case_Updated__e> notifications = new List<Case_Updated__e>(); for ...
0
votes
1answer
43 views

How to achieve code coverage for trigger after lead conversion

I have a trigger on lead and wrote a unittest but are not getting any codecoverage. What amI missing. Trigger trigger LeadTrigger on Lead (before insert, before update, before delete, after insert, ...
0
votes
0answers
28 views

Httpresponse is not getting coverd in testclass

My response was stored in static resource and I am setting fake response by staticresource method to class but my Httpresponce is not getting covered in test. @isTest global class SmartSheetUtil_Test ...
5
votes
1answer
612 views

Setting Default Value for Lightning Web Component Test

I'm writing unit test for my LWC. For some of the methods and features that I'm testing, it looks at the values of a field and then does something. For example: let field = this.template....
-1
votes
1answer
350 views

Upsert failed. First exception on row 0; first error: REQUIRED_FIELD_MISSING, on Test Class

Why do I encounter or further explanation about the error? System.DmlException: Upsert failed. First exception on row 0; first error: REQUIRED_FIELD_MISSING, Error: You can't select products until ...
0
votes
0answers
17 views

Apex Unit Tests in Lightning [duplicate]

How can I write unit tests for this Apex class in Lightning to make sure that Account and Contact records are being saved to the server?
0
votes
0answers
31 views

How to write a test class for a method that send a htttp request among other things [duplicate]

I'm trying to write the test class for a method like this. @AuraEnabled public static DynamicTableMapping getFilteredAccounts(String filterId){ List<string> headervalue = new ...
0
votes
1answer
108 views

How to Code coverage for List of Single email content in Apex Class

Apex method: webservice static boolean sendEmail(id opptyId, id duplicateid) { //Approval Email Body content PageReference SEmail = Page.Sales_ApprovalPage; SEmail.getParameters().put('...

1
5 6
7
8 9
77