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
29 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
37 views

Test class not sure how to write for this code

I have written following apex class: public with sharing class Persmissionset { @AuraEnabled public static PermissionPagerWrapper fetchPermission(Decimal pageNumber ,Integer recordToDisply) { ...
0
votes
1answer
14 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 ...
0
votes
0answers
30 views

How to write SOQL to track “Sales” User from User sObject [on hold]

I have created a Visualforce page with Apex controller.I am using wrapper class for that.I have 3 sObjects called Actual table, Ratio table and Achievement tabe where I have added user lookup field in ...
1
vote
1answer
23 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
2answers
34 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
18 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
24 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
99 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
30 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
34 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
28 views

Apex BeAwesome failed [closed]

I keep failing this test and I don't know how to fix the issue. Mostly because I'm not sure how to identify the specific lines mentioned: Class.sb_security.BeAwesome.createUser: line 133, column 1 ...
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
23 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
25 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
25 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 ...
0
votes
1answer
44 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
14 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
23 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 ...
-1
votes
0answers
14 views

Cover For Loop for this Controller in Test Class Apex Salesforce [duplicate]

I am writing a test class for my controller of VF Page but it stuck to 32% code coverage please help. How can I cover for loop for this code? I want to deploy my code to production from sandbox ...
0
votes
2answers
39 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
35 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
27 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
298 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
40 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
24 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
50 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 ...
-1
votes
0answers
26 views

Test class to test this specific code, possibly including a try-catch statement? [duplicate]

I have a trigger in Salesforce which converts Leads into Person Accounts if the 'Company Name' field is Null: Trigger AutoConvert on Lead (after insert) { LeadStatus convertStatus = [ ...
0
votes
0answers
32 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
36 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
81 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
30 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
14 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
19 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
48 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
37 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
23 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
23 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
50 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
48 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 ...
0
votes
0answers
8 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
19 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
33 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
103 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 ...