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
vote
0answers
15 views

on updating case in test class, trigger.new has the same value as trigger.oldmap even after update

I have written a test class to cover logic written on before update trigger. The test class is failing at the assert step and upon checking i found that OwnerId in both trigger.new and trigger.oldmap ...
2
votes
0answers
34 views

Apex Batch Test - works if I populate only one account, fails in setup with 2 accounts

I have written my first Apex batch processing class. It works when I manually create records and run it in my sandbox. It is very simple. We've added a set of fields that can have up to 3 values: '...
0
votes
0answers
13 views

How to write help class for the below trigger [duplicate]

trigger ActiveCountContactOnAccount on Contact (after INSERT, after UPDATE, after DELETE , after UNDELETE) { Set <Id> accountIds = new Set <Id>(); List <Account> lstAccountsToUpdate =...
4
votes
3answers
95 views

How to mock ApexTestQueueItem, AsyncApexJob, and ApexTestResult for test coverage?

I'm currently working on a set of classes that do the following: A class that when instantiated and executed, queues all Test classes in Apex to run by inserting ApexTestQueueItems. I call this one ...
6
votes
1answer
45 views

How can I unit test a http callout that uses a certificate?

The .setClientCertificateName method of the HttpRequest class requires a string that is the name of a certificate in the organization. In a unit test class, is it possible to mock this method? When I ...
0
votes
0answers
16 views

how to add Loop conditions in apex test classes? [duplicate]

Could anyone help me how to write a test class for this logic.I'm little confusing here. public with sharing class XMLparserForIds { public String XMLString1 = '<?xml version="1.0" encoding="...
0
votes
2answers
35 views

test class for future callout Json.deserialise

My Class global class CreditActionSessionObjMgmt { @future(callout=true) static webservice void deleteSessionRecord(String sessionRecIds) { if(sessionRecIds != null ) { ...
0
votes
2answers
25 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
35 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
21 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
27 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
31 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
18 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
51 views

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

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":"...
0
votes
1answer
26 views

Test Class Coverage for If Statements and calling class?

I have a controller that grabs records based on a user's email. Works fine but when it comes to the test class it does not cover these if statement: for(Order__c o: OrderDAO.selectOrder(uEmail){ ...
1
vote
0answers
44 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<...
-1
votes
0answers
21 views

apex test class for code coverage [duplicate]

Can anyone help me out in writing the test class for below apex class for code coverage if possible please. public class StudentAccountInformation { @AuraEnabled public static hed__Term__c ...
-3
votes
0answers
20 views

Help me with this test class. I am getting 0% code coverage abel to run successfully [closed]

Apex Class: global class PostRefreshSteps implements SandboxPostCopy { global void runApexClass(SandboxContext context) { System.enqueueJob(new PostRefreshDataAnonymizer()); ...
0
votes
0answers
17 views

Test data for trigger on MC IndividualEmailResult - Error on Email Send creation

I wrote a trigger on et4ae5__IndividualEmailResult__c and now need Marketing Cloud test data in my sandbox, both manually and programatically. Manually, when I try to create an ...
-1
votes
0answers
22 views

I am able to cover the class upto 32% only can U help me o cover more [duplicate]

ApexClass: public class opportunityApprovalHistoryController{ public string serverURL {get;set;} public ProcessInstanceWorkitem piw {get;set;} public boolean IsdelegatedUserId {get;set;} ...
0
votes
2answers
75 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....
-2
votes
0answers
18 views

Help me to write test class for below class [duplicate]

global class PostRefreshSteps implements SandboxPostCopy { global void runApexClass(SandboxContext context) { System.enqueueJob(new PostRefreshDataAnonymizer()); System.enqueueJob(new ...
3
votes
1answer
74 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
33 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
25 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
33 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 ...
-1
votes
0answers
11 views

Visualforce Controller Test Class [duplicate]

I have the following method in my custom controller. I'm only able to get 68% coverage in testing. In the following method I'm not getting coverage for the permission set list I'm using. This is also ...
0
votes
1answer
35 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
49 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
34 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
17 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
21 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
25 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
45 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
24 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?
-1
votes
0answers
12 views

Test class for below trigger [duplicate]

trigger bcd_Transaction on bcd_Transaction__c (before insert, before update, before delete, after insert, after update, after delete, after undelete) { bcd_TriggerLibrary.TriggerRequest ...
0
votes
1answer
41 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
33 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
58 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 ...
0
votes
1answer
34 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
21 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 ...
0
votes
2answers
41 views

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

I am trying to write unit test for a a trigger which calls batch apex which performs callout and updates the response to certain record. Trigger's psuedo code looks like: trigger AccountTrigger on ...
0
votes
2answers
182 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
28 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
29 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
23 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
21 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
27 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
19 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>,...