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
0answers
19 views

Apex Test Class fails during deployment (deleting Apex class) using Workbench [closed]

The test class works fine and passes when its run in Developer Console. But when I try to delete an apex class and run a specific test class, the deployment fails because of error in the test class. ...
0
votes
1answer
18 views

How to test trigger that compares Trigger.new with Trigger.old [duplicate]

I have a simple trigger that runs on Account update, and the only logic is a check to whether or now BillingPostalCode changes or not. This is my code: trigger ZipCodeUpdated on Account (before update)...
0
votes
0answers
19 views

I am writing a test class for apex trigger but the code coverage I am getting 69%.Can you please suggest some modification in handler or test class [duplicate]

Handler Class public class TriggerHandlerOpportunity { public static Boolean isFirstTime = true; public static void actionOnOpportunityClosure(List<Opportunity> oppList,map<id,...
-4
votes
1answer
36 views

Test class for apex with dynamic query

Hi I am new to Salesforce and I am trying to write test class for the Apex class.But I am not able to achieve it. Can someone help me? This is my apex class method. @AuraEnabled(cacheable=true) ...
0
votes
0answers
24 views

Test class for Invocable Method from Flow

I have been banging my head against the wall trying to work out how to write a test class that gets any coverage for this method, which takes values from a screenflow and returns a value back to the ...
0
votes
0answers
11 views

Test Class Fail - first error: FIELD_INTEGRITY_EXCEPTION, field integrity exception (Guest users cannot be record owners.):

I'm getting above error message when I run a test class. This class has nothing to do with Public sites/community. As per the research, I have explicitly added an OwnerId for the record. But still it ...
0
votes
0answers
13 views

code coverage in else [duplicate]

else if line is getting covered and is shown in blue/green, but the next two lines are in red. How to get that covered? } else if ((checkedSummaryPlanIds == totalSummaryPlanIds) && (...
-2
votes
1answer
46 views

Strange behavior of test [closed]

I have method which works when opportunity status become 'Won'. It checks if this opportunity doesn't have activated test orders. That is it: public static void validateIfOppStatusCanBecomeWonOrLost( ...
0
votes
0answers
53 views

How do I write test methods for a @future method in a SandboxPostCopy class?

My team uses a sandbox for user onboarding, so I wrote a SandboxPostCopy class to populate the training sandbox with sets of records and create test users on refresh. The class compiles and, as far as ...
-1
votes
1answer
32 views

Testing Code Coverage [duplicate]

I have only 73% code coverage, however, I've created multiple tests, all which pass. Here is the controller code: public class CaseController { public ApexPages.StandardController stdCntrlr {get; ...
0
votes
1answer
40 views

Writing test class to change Inactive User to Queue

I'm a beginner APEX developer in a bit of a tricky spot. As we know, leads get assigned to sellers. However, sellers get fired from time to time causing them to become inactive users. The issue then ...
0
votes
1answer
28 views

Complicated Trigger Handler Need to Replicate Trigger Context Values

Let me begin by saying, I know that this could be significantly better code if using the Trigger.newMap and Trigger.oldMap I have run into a situation though where I need to reuse a class within a ...
-2
votes
0answers
35 views

After inset trigger doesn't fire

I have some code which is creating QuoteLineItems and a trigger which fires when insert QuoteLineItems. Trigger works fine in UI but when I try to test it in apex test class it doesn't work. ...
0
votes
0answers
20 views

Quotelineitems aren't creating from OpporunityLineItems in apex test class

My problem is that QuoteLineItem records aren't creating from OpporunityLineItem records in apex test class. As I know it is a standard functionality of salesforce to create QuoteLineItem records when ...
0
votes
1answer
38 views

How can i test my Apex method

I am not sure how to write test class for this method. Any help would be greatly appreciated! @AuraEnabled(cacheable=true) public static List<Map<String, String>> getPickListValues() { ...
1
vote
0answers
29 views

Error - pricebook entry is in a different pricebook than the one assigned to the opportunity....Except it's not

As you can see i insert a pricebook assign that pricebook to the opportunity, assign the pricebook entry to that pricebook and assigned the entry to the opportunity line item. So opportunitylineitem....
-3
votes
0answers
40 views

How do we write Apex Test Class for a trigger that calls an Invocable method via a Webservice

I get the error Methods defined as TestMethod do not support Web service callouts : No response although I have used HttpCalloutMock. Can't figure where I am going wrong. The trigger on my Lead ...
1
vote
2answers
59 views

How to use a constant in SOQL in a test class

I have the following test class: @isTest(SeeAllData=false) private with sharing class classNameTest { @isTest static testMethod void methodName(){ // declare a constant ...
0
votes
1answer
34 views

apex code coverage for error records in database method

How to get the coverage for the // dml operation failed part? // records to be updated received from json jsonBody = '[{"count__c":"445", "downloads__c":"340"}, ...
0
votes
1answer
39 views

How can I get the full value of a variable while debugging Apex?

I'm using VS Code with the salesforce extensions to debug a test method. A query executed by the method is returning no records when I think it should be returning one. So I click on the "Debug ...
0
votes
1answer
38 views

Stub rest api test negative and positive result

I have class where using insertData() method and using stub. I want insertData stub return positive and negative results. How can i do it? Inserted data also is another method which I stub. So its ...
0
votes
1answer
50 views

Custom metadata type in Stub api

I am using trying to stub my class, but I have get and set for custom metadata. I know that I cannot stub get and set. Is there exist any design for using it in stub? Or I must just hardcode it and ...
0
votes
1answer
29 views

JEST Test LWC - render on conditional

How to write a jest test on conditional rendering? so I have a page in that page few input and combobox and when the combobox selected to a particular type which is accepted then I display the input ...
1
vote
1answer
44 views

How do I create Duplicate/Matching Rules through Apex code for an Apex test class?

I recently wrote an API to implement Account/Contact Duplicate/Matching rules for a connected app. It all works fine. It does the same thing that Salesforce does for these rules. It pretty much ...
0
votes
0answers
39 views

How do I write a test for my Trigger? [duplicate]

I'm currently in the test phase of my project. I suppose to write a test on my triggers if someone has the good syntax for that (I've tried but it didn't work): here my triggers 1/ trigger ...
1
vote
1answer
68 views

Stub api with static methods

I have a global class with a static method which makes post callout and I want to use Stub API, but I don't get how to do it when a method is static. I understand what to do inside mock classes, but I ...
0
votes
0answers
25 views

Problem with Testing a New Quote Controller Extension

Updated Sep 10, 2021; see at end. I have written a VF New Quote page that uses a controller extension. The purpose of the extension is to initialize certain custom fields in the Quote and the ...
0
votes
1answer
29 views

I need help with this error " first error: UNABLE_TO_LOCK_ROW, unable to obtain exclusive access to this record or 1 records: 01s4J000002l5eqQAA: []"

I am trying to add Service Contracts and the Contract Line Items from Order Products. Also I am adding Entitlements and Referencing Proforma Invoices at same time. Following is my Code... public class ...
0
votes
0answers
24 views

Test class try catch on rest callout [duplicate]

So i am making post request and catch error by checking status code and by try catch too. And how can i test try catch block? I think mock response is useless here. So requst looks like: public void ...
-2
votes
0answers
21 views

could you please help me write a test class for the attached picture [duplicate]

In the attached picture code which is not covered could you please help me to cover those lines
0
votes
1answer
23 views

Test Addition to a List or Set using Test class [duplicate]

I have the following code which is fetching only First Name from Contact where Account Name is 'United Oil & Gas, UK'. public class ContactUK { public List<string> viewcontactUK(...
-2
votes
1answer
54 views

Test Class Coverage TriggerDispatcher

Unable to cover this class , this is a common class for all triggers. Please help. public virtual class TriggerDispatcherBase implements ITriggerDispatcher { private static ...
-3
votes
1answer
36 views

My test class does not enter the execute method

I have a class scheduler that calls my bacth class, it executes the start method but doesn't enter the execute, below are my classes My class Schedulable global class ...
7
votes
0answers
44 views

Is there a way to force a Platform Event Trigger to honor the PlatformEventSubscriberConfig in unit tests?

I'm attempting to move an integration away from using Custom SObjects and to using Platform Events out of a concern for storage space (and also so our eventual automation of this integration won't ...
0
votes
0answers
19 views

Test class code coverage is 35 % for Opportunity Trigger Handler can you please help me to get the test class 75% code coverage please help me [duplicate]

@isTest public class OpportunityTriggerHandler_Test{ private static testMethod void test_isDisabled_UseCase1(){ OpportunityTriggerHandler obj01 = new OpportunityTriggerHandler(); obj01....
2
votes
0answers
54 views

Apex Test not able to execute Queueable and Future in same user context?

Scenario -> Queueable calls a Future method In business process the Queueable calls another future method and future executes in same user context as its having some CRUD and FLS checks. Now when ...
0
votes
1answer
30 views

The Test.isRunningTest() function is not working

I am using if(Test.isRunningTest()) condition to set the response code to 200 for code coverage related to my HTTP callout class, so that the success scenario gets covered. But in the coverage details ...
-2
votes
0answers
22 views

Apex code coverage for if condition [duplicate]

I am new to apex test class. I need help for w.r.t test class for below condition. If any one having exp on writing test please guide me . if (caseList.size() > 0){ List<...
1
vote
1answer
34 views

Testing Trigger

My code comes out as 0% coverage even though I have no errors. What am I doing wrong? @IsTest public class TestPlayerTrigger { @IsTest static void RacquetRequest(){ List<...
0
votes
0answers
22 views

Test Class on Approval Action Apex Class

I have an Invocable apex class for approval actions. I am trying to get test coverage on this. But I must be missing something as there are no lines of code coverage. I am new to apex so its ...
0
votes
2answers
46 views

Test data setup vs. test data factory in salesforce

I know how test data setup method and test data factory works. But I was wondering, if we can create test data in data setup method then why do we need the test data factory class? Is the data factory ...
0
votes
0answers
15 views

Need test class for preventing email change on contact after user has entered the email earlier [duplicate]

Apex class: public class Contacttriggerhandler { public static void preventEmailChange(list<contact> conlist,Map<Id,Contact> myoldmap){ for(Contact newcon: ...
0
votes
1answer
37 views

How to use Opportunity.PartnerAccountId in a unit test?

I want to create a unit test to test code that works with PartnerAccount information on Opportunity. However, no matter what I try, I can't get the PartnerAccountId to populate on an Opportunity ...
0
votes
0answers
28 views

Simulate Campaign Influence record creation in Test Classes

We have enabled Customizable Campaign Influence in one of our orgs. There we are using Primary Campaign Source Model as the default model since we wanted to migrate from the old Campaign Influence ...
2
votes
1answer
73 views

Field level security pain in Apex tests when using packaging 2

In line with current security standards, we use with security_enforced extensively in our code. When doing CI (Continuous Integration) builds or working interactively we use sfdx force:user:permset:...
0
votes
0answers
18 views

Test.loadData is not inserting data for Producer object

I am working on a Data Factory test class and I was able to successfully load relational data for Account, Case, WorkOrder, User, InsurancePolicy and couple of other custom objects by providing Id in ...
-2
votes
1answer
22 views

How to call a method with arguement in a test class

private void insertRawData(LocationSOHMapSummary locSohMapObj) { List<Dummy_Object__c> accToTerrList = new List<Dummy_Object__c>(); for(...
0
votes
1answer
32 views

How to properly test invocable callout class

I am a total beginner in Apex, however I created the following class that calls an external API endpoint and is invoked by a flow: public class SubscribeToStatuspage { @InvocableMethod(label='Call ...
0
votes
1answer
20 views

Simple test class - trigger not fired

Feels like a DOH moment, but: I have an org which I need to deactivate all it's triggers, and remove old apex classes. Tedious, but while trying a simple trigger, it's not firing from a test class: I ...
0
votes
1answer
35 views

Why my test class is not covering execute method?

Class: global class SendNewAccountEmailBatch implements Database.Batchable<sObject>, Database.Stateful { List<string> sendingTo; EmailTemplate mailTemplateRcd; global Map<...

1
2 3 4 5
87