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
44 views

Overall Code Coverage including unrelated classes as well

I have a sandbox org where I've created a trigger that calls another class containing a future method for final HTTP request. I have also created a test class and MockHttpRequest for it which is able ...
0
votes
0answers
1k views

Advanced Apex Specialist - challenge 8 - Challenge Not yet complete… here's what's wrong

I have this error when I am trying to complete Salesforce Advanced Apex Specialist. Ensure that you have at least 12 products created and that OrderExtension is still working as specified in the ...
0
votes
2answers
54 views

System.DmlException: Insert failed. First exception on row 0; first error: CANNOT_INSERT_UPDATE_ACTIVATE_ENTITY

Below error I got while running test class.My test class results fail.Anyone have some idea please share with me. Error Details : System.DmlException: Insert failed. First exception on row 0; ...
0
votes
1answer
52 views

Rest Callout Apex Test: How to Test @AuraEnabled Method?

guys! I have a problem with one method in my Apex class, which I need to cover by tests. This class uses "GET" callout and checks, if the input field is empty (null). If it is, the @AuraEnabled ...
0
votes
1answer
70 views

Rest Callout Test Class : How to Cover @AuraEnabled method?

I'm new to Salesforce and now I'm struggling with one task. I need to make test class, but I'm wondering: how do you cover the second @auraEnabled method with If statement? Here is the code: Apex ...
0
votes
1answer
21 views

In Test class no result for Order.Account.RecordTypeId

In a test class, I want to update Account information depending on the record type. The information to update comes from the Order object. I have created a test account with the according record type. ...
-3
votes
2answers
75 views

How to convert String to list<object> for a test class [closed]

I have a Json getting it in Aura Controller, and for test class, I am mimicking the Json into a string . Original JSON = [{"subid":"a4wgwe00000DfDRAA0","totalgs":"25","Revenue":"17"},{"subid":"...
1
vote
0answers
50 views

Test Class failing with Too many SOQL queries: 101

My test class is public static testMethod void loanSetDelegatedApprovers() { list<User> userList = new list<User>(); list<Approval_Delegate__c> adList = new list<...
0
votes
2answers
251 views

userinfo.getuserid() returning null in test class

I have a test class which inserts partner user for testing. So, when I pass userinfor.getuserID(), it is returning null due to which my test class is failing with error "System....
3
votes
1answer
95 views

Apex batch class test not running execute?

I have written a batch class to mark a certain number of an object in a date range to be marked for review, and it is working when called on from a visualforce page, but it does not work when called ...
0
votes
0answers
19 views

How to write test class for the below class. I tried alot but it not covering [duplicate]

public class LeadAssignment { public Set<String> nullParamsSet; public LeadAssignment(){ nullParamsSet = new Set<String>(); for (NullParameters__c np : ...
1
vote
2answers
39 views

Question about making a test class for my before update trigger that uses custom objects and uploading via change set

I’m new to apex and I am currently trying to upload my first trigger to production from my sandbox using change sets .Its purpose Is to update the date field of the site object with the most recent ...
-2
votes
1answer
69 views

test class for apex class creating multiple object records [duplicate]

Can anyone helps me out in writing the test class for below apex class. I know that I should not post it here asking for this kind of questions but as I am new to apex and I need to deploy so I was ...
0
votes
1answer
40 views

Writing test class for wrapper class to simulate the business process

I am trying to write a test class for a Wrapper class. The wrapper class pulls one objects to make it as a checkbox list. Could anyone help me to adjust the code I wrote below? I have written test ...
0
votes
1answer
72 views

Too many SOQL queries error encountered when running the class in Sandbox but not in Production

I have experienced a bunch of test classes fail to pass in a Sandbox, but execute fine in Production. Has anyone some good tips on what look out specifically? I think the code itself is not ...
0
votes
2answers
143 views

apex test class is failing on run

Can anyone help me out in writing test class for the below apex class. I tried test class but when I was running the test then I am getting below error. System.DmlException: Insert failed. First ...
0
votes
1answer
104 views

issue with userdata in test class for auto registration handler class

I have a test class which is as below @isTest private class KC_Reg_Handler_Test { static testMethod void testCreateAndUpdateUser() { KC_RegHandler handler = new KC_RegHandler (); ...
2
votes
0answers
70 views

How to test big object creation in unit test

I have an apex trigger which fires a platform event. And in the platform event trigger, it creates a big object. My unit test code is pretty simple and looks like below: Account acc = ...
2
votes
1answer
29 views

test class for opportunity trigger not fully testing the entire code

my trigger trigger EmailTest on Opportunity (before insert) { id ac; List<Messaging.SingleEmailMessage> mails = new List<Messaging.SingleEmailMessage>(); for (Opportunity opp : trigger....
0
votes
1answer
26 views

Quicker way to get covered lines of a class

I am working on a unit test of a class in developer console. My target is to achieve a certain level of coverage. I am on edge of reaching my coverage target, so I need to know the number of lines ...
-1
votes
2answers
50 views

How to cover this code? [duplicate]

How to cover this code? Test class Code @isTest static void getPageNumberListTest(){ Controller controller = new Controller(); controller.TotalPages=10; controller....
0
votes
0answers
26 views

Create SObject metadata in unit test

We are using sobject settings in our package. Is it possible to create metadata sobject in the unit test?
0
votes
1answer
48 views

APEX test script to web server with a static time stamp doget cakk and HttpGet

New to writing test scripts. Looking for help in error in Unexpected token 'Lead' for my test code. I have a static field that pulls off time stamp to only pull data after a certain time. I am ...
0
votes
1answer
55 views

List must not have two identically equal elements: bulk test

I have after insert Trigger and I'm trying to test it with this logic (for bulk testing). It's a little test from Execute Anonymous Window: List<Lib__c> lb = new List<Lib__c>(); string s =...
0
votes
1answer
670 views

Advanced Apex Specialist Superbadge Step 5

I am blocked in the step 5 of Advanced Apex Specialist Superbadge with the following message : When checking the developer console i found that the challenge tests directly the VerifyQuantityOrdered ...
1
vote
1answer
3k views

Running unit test class from VSCode

I am new to VSCode. The Org is setup in VSCode. ForceCode, vforce, Salesforce CLI Integration and some other extensions installed in the VSCode. Org is authorized. I am able to save my changes in ...
-2
votes
2answers
33 views

Apex Test Failure: System.ListException: List index out of bounds: 0 Stack Trace: Class.CaseExtensionTest.test_Attachment: line 136, column 1

Getting the Test Coverage error: Apex Test Failure: System.ListException: List index out of bounds: 0 Stack Trace: Class.CaseExtensionTest.test_Attachment: static testMethod void ...
1
vote
2answers
194 views

Testing a trigger calling batch class for making a callout gives System.CalloutException

I am trying to write unit test for a trigger which calls batch apex performing callouts first then updates the response to those record. Trigger's psuedo code looks like: trigger AccountTrigger on ...
0
votes
2answers
680 views

Trailhead Apex Specialist Super Badge test class error

I am trying to complete the challenge number#5 on the Advanced Apex Specialist Super badge and I am stuck with an error. I am getting an error stating that the test method doesn't have proper ...
0
votes
1answer
63 views

Visualforce email template can't see data when run in unit test

I currently have a Batchable process that will send emails to some users: global class ExpiryNotificationHandler implements Database.Batchable<sObject> { global System.Iterable<sObject&...
1
vote
1answer
175 views

Field not writable: ContentVersion.FileType

In the following test method: static testMethod void testEmailWithAttachments() { ContentVersion contentVersion = new ContentVersion(); contentVersion.FileType = 'Text'; ...
0
votes
0answers
68 views

Cover return Null in test class for code coverage

Here is my test class and class. global class ACN_NavigationImplementationTemplate implements ACN_NavigationProviderService { global ACN_NavigationLibrary.NavigationList GetNavigationList (...
1
vote
1answer
34 views

how to make test class for controller with parameter canvas.toDataURL()

I made extension class and VF page for getting signature image. I confirmed it works well through many test . And then, I need to make test class to deploy that extension class into production org. ...
1
vote
1answer
69 views

Apex test class throwing error for lead conversion

I am writing a test class but on running I am getting the following error continuously. System.DmlException: ConvertLead failed. First exception on row 0; first error: ...
1
vote
0answers
23 views

Test Class for Batch Apex Schedulable batch Process [duplicate]

I need help in writing test class for the below Apex Schedulable batch Process. Can anyone help me out. global class CLM_Batch_ExpireAgreements implements Database.Batchable<sObject>,...
1
vote
0answers
32 views

trigger getting 0 code coverage even though test class is successfully running

I wrote a trigger and a test class to get the code coverage. My test class is running successfully but I am getting 0% code coverage, can anyone helps me out in this issue if possible please. ...
-1
votes
1answer
35 views

Need help in writing Test Class for Rest API Class [duplicate]

I have a REST API class which updates the user status in external system when the user status is changed in Salesforce. Below is the code public class AccUpdateController { @future(callout=true) ...
0
votes
2answers
39 views

Adding time gap between two call of batches in test class

I had an issue in my batch class, it was picking the same data to process when it is already run for the same earlier. If the data is processed once, that batch should not pick that data again in the ...
0
votes
0answers
25 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
43 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 ...
0
votes
1answer
182 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
50 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 ...
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(...
0
votes
2answers
63 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
44 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
28 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
47 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
115 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
38 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 ...

1 3 4 5 6 7 76