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

Create sobject record type in unit test

We have a logic that does changes depends on empty/master record type or a custom one. Is it possible to create a test record type and assign it to the record? We wanted to add unit test coverage for ...
0
votes
0answers
15 views

How to retrieve second set of email invocations in unit test? [duplicate]

I'm triggering an apex email in my unit test. I would like to assert that 1 email has been invoked. I can see from the logs that it is invoked. However, it seems that my code is looking at the wrong ...
0
votes
0answers
9 views

How to write test class for the below code: [duplicate]

Iam trying to create the testclass for the apex trigger for the account update trigger here iam attesting my code which i have written for the helperclass (trigger) public with sharing class ...
0
votes
0answers
39 views

How to cover Http Response class method and AccessToken Method? [duplicate]

I have to increase the code coverage of the class. In order to do that, I have written code coverage for the constructors. This is the class: public class LendingTIDOutboundIntegrationHelper { ...
0
votes
0answers
16 views

No Coverage for CaseComment Trigger

I have a Trigger on CaseComment Object in my Org which has only one line of Code in It to call a static method from another apex class. But the trigger has 0% coverage. I have written a test Class to ...
-6
votes
0answers
36 views

Pls help for Test class for Batch class on Flow Interview Object [closed]

please help in writing test class for below code. my code: public class FlowInterviewHandler implements Database.Batchable<SObject> { Integer miutescustomLabelValue = Integer.ValueOf(System....
0
votes
0answers
28 views

Unable to do code coverage, now my code coverage is 33% ,can anyone help for 75% [duplicate]

Extension Controller: public with sharing class CreateQuotePDFController { public list<QuoteLineItem> quoteLineItemsList{get;set;} public Id getid{get;set;} public Double ...
-1
votes
1answer
21 views

How to write test class for below Vf Page Controller [duplicate]

Class public with sharing class CreateQuotePDFController { public list<QuoteLineItem> quoteLineItemsList{get;set;} public Id getid{get;set;} public Double grandTotalTax{get;set;} ...
7
votes
2answers
198 views

what/who.(RecordType.Id vs RecordTypeId) SF Bug

Task[] tasks = [SELECT Id FROM Task WHERE What.RecordType.Id = :AccountsHelper.getPersonAccountRecordType().Id LIMIT 1]; System.debug('tasks size : ' + tasks.size()); Task[] tasks2 = [SELECT Id FROM ...
2
votes
1answer
34 views

Unable to override @salesforce/community/basePath mock within jest test

I'm trying to mock the @salesforce/community/basePath scoped module with different values for each jest test. I've mocked it globally : jest.mock( "@salesforce/i18n/lang", () => {...
0
votes
0answers
12 views

How do I create Sales Cadence Records Via Apex Test Code?

I created an Apex CDC Trigger on the ActionCadenceTracker object via the ActionCadenceTrackerChangeEvent to update a Lead's status when the sales cadence is completed. I'd like to write Apex test code ...
0
votes
0answers
28 views

Formula.recalculateFormulas in Before Trigger Error

We have a before insert trigger on which we are trying to recalculate formulas using Formula.recalculateFormulas(). We specifically are doing this on person accounts. This error is being produced: ...
-2
votes
0answers
15 views

help me with a test class for the following trigger [duplicate]

trigger OracleQuoteTrigger on cafsl__Oracle_Quote__c (after Insert,after Update) { if(Trigger.isInsert && Trigger.isAfter){ OracelQuoteTriggerHandler.afterInsert(trigger.new); }...
-2
votes
0answers
31 views

aura testing problem

below is my apex method and test the problem im getting is the contact is not deleting even though the test does cover the method. the test is not failing but when i use system.debug after calling the ...
0
votes
0answers
23 views

testing question

writing test for aura apex controller and one of the methods being tested is just returning a list of contacts from a SOQL query my test is @isTest public static void getContactsTest() { List&...
0
votes
0answers
20 views

How to get coverage for return value from flow in test class?

I have a below class and test class. Flow called in this class call another apex action that get cases through integration for the Logged In user. I am not able to increase test coverage above 43%. ...
0
votes
0answers
27 views

How to write test class for return type methods? [duplicate]

I am really new to Apex and test classes. I am having issues while writing the test for the below class. Can someone please help me? At least guide me what data should I insert first and mainly how to ...
0
votes
1answer
19 views

unable to insert OpportunityLineItem.PricebookEntry

This is the code - Apex code - public static void createnewOrderBillingItem (OpportunityLineItem ChildOpptyLines,Id OrderId,Integer Qty){ if(((ChildOpptyLines.NRC__c > 0) && (...
0
votes
1answer
27 views

How to get rid of Apex class that is not in use

I want to delete an apex class that is not used anymore but has dependencies with Flows and LWC etc. What would be an ideal way to retire the apex class? Commenting out the lines or deleting the class ...
0
votes
1answer
17 views

Is there a way to persist PlatformEvents that are sent during tests?

My question is: Is there a way to persist PlatformEvents that are sent during tests? What I want to achieve: I would like to log some warnings during the tests, which I could read later.
0
votes
0answers
22 views

How do I write a test class [duplicate]

I've recently written my first piece of apex and I've gone through the trailhead stuff about writing test classes but I don't really understand how I test each piece of the code. Can anyone give me ...
-1
votes
0answers
25 views

Hi every one, pls help me with test class for trigger [duplicate]

trigger NBAFieldUpdate on Account (after update){ if(AvoidRecursion.isFirstRun()) { map<id,Account> acctId_to_acct = new map<id,Account>(); for(Account a : trigger.new){...
0
votes
1answer
27 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)...
-4
votes
1answer
40 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
27 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
18 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) && (...
0
votes
0answers
54 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
36 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
44 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
29 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 ...
0
votes
0answers
22 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
40 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
1answer
31 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....
1
vote
2answers
65 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
35 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
44 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
38 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
63 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
78 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
25 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 ...
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
48 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 ...

1
2 3 4 5
88