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
1answer
26 views

Not able to fix the issue in test class

I have a batch class and I wrote test class for the same. The test class is throwing an error at Date Type. Can someone help me how to fix the issue. Batch Class public without sharing class ...
1
vote
1answer
12 views

Delete Accounts restriction still works in unit tests

The permission to delete Accounts is unchecked in test User Profile according to this trailhead article. https://trailhead.salesforce.com/en/content/learn/projects/protect-your-data-in-salesforce/...
1
vote
1answer
10 views

querying inserted sObjects in test class returning list has no rows for assignment

this is my test class: @isTest public class Test_LWCOrder { private static Order__c order; private static ERPvs__Productos_Pedidos__c pp; private static Erpvs__Envio__c envio; @...
0
votes
1answer
18 views

Process Builder doesn't seem to execute from Test Methods

I have Process Builders built on Cases which makes the following job: Change Owner to Queue on Create Change Status to 'New' on Create, to 'In Progress' on Accept, and changes parent case Status to '...
4
votes
1answer
53 views

Does change set validation run tests within the change set class or the class already in the org or a merged version of both classes?

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 ...
1
vote
1answer
26 views

How to test json.deserializeUntyped in trigger

I have a platform event trigger that takes in a json string which contains an array of objects. My postman test call looks like this: "testCodeList__c":"[{\"testCode\":\&...
5
votes
1answer
104 views

Queueable apex runs in System admin mode even after written in System.runAs mode

Queueable class from Test context runs in test runner mode and not in System.runAs user. This is strange behaviour. Here is the snippet. Any idea? User internalUser = // Created Internal User with ...
0
votes
0answers
19 views

What are possible side effects of “Compile all classes” in production? [duplicate]

When I validate a change set with RunLocalTests in production (as well as using the CLI with that flag for CI/CD and packaging integration) there was a class that was erroring out as a dependency. I'...
0
votes
0answers
15 views

Test email sending in Batch class

I have created a batch that sends in email anytime the status of an article is updated. I am trying to write a test class for the batch but I only manage to cover 45% of the class. I struggle to cover ...
0
votes
0answers
11 views

How can I increase my test class code coverage above than 75 % for vf controller apex class? [duplicate]

I am new in salesforce development and I am new in test classes. Now I am trying to increase code coverage for vf page controller. Now it's showing 50% but I need more than 75% .. please any one help ...
-1
votes
1answer
49 views

Error Non static method cannot be referenced from a static context

Test class: @isTest private with sharing class Genereratortest { @TestSetup static void createPayloadtest() { List<_Site__c> studySites = new List<_Study_Site__c>{ ...
0
votes
0answers
24 views

test System field on Batch class

I have a batch that automatically archives any articles with a Status (Fixed) and published for more than 30 days (using a custom setting to verify the number of days). But I struggle to cover the ...
0
votes
0answers
20 views

Writing a test class for an invocable method that combines the UTC dates of the beginning of the year and the current time [duplicate]

I built an apex class for an invocable method that runs from a flow to generate a link to authenticate a user to a community. The apex class updates a field on the contact record when the contact (a ...
0
votes
0answers
43 views

Where is the data in batch class coming from?

First of all, I'm very new to salesforce so It's possible that I'm ignoring something very basic. I was writing a test class for the following batch (I've removed all the irrelevant parts). global ...
0
votes
1answer
19 views

How to set controller date in test class

how to set a date in the test class, Thanks in advance. visual force page: <apex:page controller=IntegrationController" docType="html-5.0"> <apex:outputPanel > ...
-3
votes
0answers
15 views

I am new to test class can you provide test class for below class [duplicate]

I am new to salesforce can you provide test class for below class. Apex class: public with sharing class AccountHandlerClass implements GlobalUtilInterface { public void beforeInsert(SObject SO) { ...
0
votes
1answer
44 views

how to Unit Test a failure to deactivate a user (DML failure)

/** * Restful resource Patch (update record) request passes user federation Identifier * @param emailId */ @HttpPatch global static List<ResponseWrapper> DeactivateUser_Restful_Ctl(string ...
0
votes
1answer
17 views

Test coverage is 100% but assertion is failing

I have written a test class for a sample apex code but the issue with this is that the code coverage which is being displayed is 100% although there is an assertion exception Apex Class: trigger ...
1
vote
0answers
38 views

Proper way to mock svg html template in Jest?

I want to create lwc component which selectively renders svg from html template files. I wonder how to mock that templates for the needs of JEST test. Import the same templates for component and test ...
2
votes
1answer
336 views

How to ensure 100% code coverage for isSandbox() method branches [duplicate]

I am using the isSandbox() method outlined in the article Determine the organization's edition and environment via APEX code, to determine whether my current org. is a Sandbox. Sample code from the ...
0
votes
1answer
28 views

Trying to write my first test class but I can't wrap my head around it

I wrote a simple class that calculates the amount to discount on a opportunity based on a Discount_Level__c field, which is a picklist with three different values. Here's the class: public with ...
0
votes
0answers
44 views

How to Write Test Class for If Condition [duplicate]

How to Write Test Class for If Condition... This is my Trigger... trigger TierPricingOffers on OpportunityLineItem (before Insert,before Update,before delete) { if(trigger.isBefore) { Set<...
0
votes
1answer
25 views

Preparing Test class for parameterized beforeDelete()?

I'm trying to create test class for beforeDelete().But I'm confusing on passing parameters.Kindly help me. Apex Class : public class TriggerService { public static void beforeDelete(List<...
0
votes
1answer
30 views

How do I insert an ID into a test class?

I have this SOQL in my class that I am testing: //The ID of a document stored in a Salesforce library final Id myFileId = [SELECT id from ContentVersion where ContentDocumentId = 'ContentID' LIMIT 1 ...
2
votes
1answer
21 views

Classes with no sharing declaration don't behave the same as those “without sharing”

I had been under the impression that omitting a sharing declaration was equivalent to using "without sharing", but that appears to not always be true. For example, if I have legacy code like ...
0
votes
0answers
14 views

testing “without sharing” classes without using runAs

Is there any way to test the following code using either unit tests or fflib mocks? public class casesService { public without sharing class ElevatedContext { public void updateCases(List<...
1
vote
2answers
51 views

Testing NavigationMenuItems without @TestVisible

I have a method to get the NavigationMenuItems for a provided Community is is possible to test this without using @TestVisible? So far I have tried to insert a community and NavigationMenu and ...
0
votes
0answers
34 views

Apex Test Class — Code Coverage [duplicate]

Ive created an apex class that pulls in certain leads and then feeds all the IDs into a round robin assigner apex class. Im not a developer but Ive been able to hack together enough to get this ...
1
vote
0answers
19 views

Is there a workaround for testing criteria based sharing rules? [duplicate]

From the Salesforce documentation, you cannot directly test criteria based sharing rules. I'm just thinking about if there is a work around for this limitation - possibly by creating __share records ...
2
votes
1answer
416 views

Why does the test fail?

I am learning testing and came across the following: why is my test method not working as I expect and returning 0 records to me? //test method @isTest static void searchContacts(){ Contact ...
0
votes
0answers
36 views

Trailhead Negative Test Class at 100% but still fails trailhead

I am having an issue passing the Write Negative Tests Trailhead. Create a new class named Calculator_Tests Write positive and negative tests for the Calculator class Be sure to use @testSetup methods ...
0
votes
1answer
26 views

After a successful run test class the main class coverage is showing none

Hello Techies, I have a wired issue After a Successful run test class the main class coverage is showing none. Below is the screenshot. If anyone also faces this issue then please let me know.
1
vote
1answer
34 views

How can I remove classes that I am not testing from the list of “Overall Code Coverage”? [closed]

I started researching testing and I had this question. The list contains all the classes that I managed to create during the training. Can only the necessary ones be left here and how to do it?
0
votes
1answer
25 views

Error: Compile Error: Extra ')',

I'm trying to call My apex class in Test calss at that time I got an error. Please anyone help me to resolve. Test Calss @isTest private class UnplannedCallsTest{ @isTest static void ...
0
votes
0answers
15 views

i want this apex class test class above 85% [duplicate]

global static List<String> checkEmailExists(String emailtocheck, String phone,String memberId){ OmniOperations.PhoneNumberValidation emailObj = new OmniOperations....
0
votes
1answer
38 views

Scheduled Apex Class Not Executing in Test Class [duplicate]

Hey guys so I’m having trouble with testing my scheduled apex class that is sending an email. The problem that is occurring for me is that when I click test, my System.assertEquals are not true ...
0
votes
0answers
15 views

Apex parsor class test coverge. I did all thing correct but coverage for parsor is not proper [duplicate]

I have a apex class for making call out and response is Parser using a Parser class. Now i wrote a test class but the Parser class is not getting covered properly. Do any one have any idea how to get ...
0
votes
1answer
10 views

Test class coverage for QuoteLineModel and QuoteLineGroupModel apex class [duplicate]

need help in test class code coverage for below classes public class QuoteLineModel { public SBQQ__QuoteLine__c record; public SBQQ__QuoteLine__c record; public Boolean amountDiscountProrated; public ...
0
votes
0answers
21 views

need help to write test case [duplicate]

here is the class in which we are writing code when an attcahment is created following logic should run.the test class that i had written had a code coverage of 63%.test class pasted below.need help ...
0
votes
1answer
33 views

Creating a dummy Visualforce page for an apex test class

Im working on creating a test class for two apex classes(one is scheduled another is batch apex. The scheduled is linked to the batch apex to have it run regularly.) The issue that I am running into ...
1
vote
1answer
36 views

How do I mock external objects for the purpose of testing a batch Apex class?

I have a Batchable Apex class that queries against an external object in the QueryLocator. I need to be able to write a test against the batch apex class to achieve coverage. I've looked this answer ...
1
vote
1answer
75 views

Test class for Object<ANY>

I'm having issues understanding some concepts of Object in apex and trying to write a test class for it. Here is my class global void myLeadsCities(Map<String,Object> inputJsonMap) { Set<...
0
votes
1answer
26 views

Code Coverage is passing in Sandbox with 84% but when deploying to prod its failing with 46% Code coverage

I'm deploying an apex class and Test class which is covering with 84% in Sandbox however when deploying in Production, its failing and says "Your code coverage is 46%. You need at least 75% ...
1
vote
2answers
32 views

Record insert fail during Apex Trigger Before Insert testing

I am trying to create a test class for my Before Insert Trigger. The trigger appears to be working well in sandbox. Looking at my debugs, it looks like I have everything there, and that the trigger ...
1
vote
1answer
33 views

What to check in a test method that doesn't modify or return a value?

I have a queueable class that gets a token then enqueues another queueable with the retrieved token. The second queueable do the DML and everything. This TokenQueueable class doesn't modify or return ...
1
vote
1answer
45 views

Why are child records I'm inserting in my test class not appearing?

an amateur apex user here and I have a question which I've tried to distill below as much as I can. I have a class OrderTriggerHandlerV2 which fires when Order.OriginalContractedOrder__c gets filled ...
4
votes
1answer
40 views

What changed with the creation of OpportunityLineItemSchedule records in the v38.0 (Winter17) release in a test context?

I'm in the process of bringing the all API versions up to the current release in an old project and have run into a breaking change with how OpportunityLineItemSchedule records are created. In v37.0 ...
0
votes
2answers
36 views

SFDX - Identify tests for a specific class

I am working on a github action that is supposed to validate a "delta" package of changes in a merge request in a target sandbox. For this validation process i am not supposed to run all ...
0
votes
0answers
26 views

Help Class for Trigger [duplicate]

Can someone help me how to write test class for the below trigger. trigger AccountOwnerUpdate on Account (before insert, before update) { Set<Id> accIds = new Set<Id>(); List<...
0
votes
0answers
19 views

How to get over OrgWideAddress in Test Class [duplicate]

Is there any way to "skip" the lines or either create the data without using @SeeAllData=ture? I didn't found a solution without using it. Thanks.

1
2 3 4 5
85