Questions tagged [test-setup]

The tag has no usage guidance.

Filter by
Sorted by
Tagged with
1 vote
1 answer
36 views

Test Class for failed flow interviews

I would really appreciate some help on this. We are creating a batch class which convert failed flow interviews into error log records which will in turn be sent over to an external logging platform, ...
0 votes
1 answer
40 views

Lwc controller apex test class

Say I haven apex class that is being used in a lwc to bring in the name of a group via a wired method to variable accid. The apex class looks something like this. Public controllerclass { Public ...
  • 1
1 vote
1 answer
74 views

How to use methods from Assert Class

According to this doc from the Apex reference guide, I can use methods from the Assert class in my test methods but when I am trying this in my code I am getting an error message:- "Variable ...
  • 13
0 votes
0 answers
21 views

How to write/put data for map in a test method for following method? [duplicate]

@future (callout=true) public static void fetchDetailsAndUpdaterandCustomer(String emailid, String empid, String jwttoken) { // rand_App_Customer__c customer = [SELECT Id,Name, ...
0 votes
0 answers
50 views

How to cover for loop with wrapper class in test method?

I am not getting coverage from " for (FileInfoWrapper file : caseInfo.files)" @AuraEnabled public static String loadData(String strCaseInfo) { System.debug('caseInfo ' + strCaseInfo); ...
-2 votes
1 answer
106 views

Test Class for custom metadata

Getting the error of List has no row assignment in test class. How should i query the custom metadata in test class Apex - public with sharing class GetAccountsController { @AuraEnabled(cacheable=...
0 votes
0 answers
18 views

test class for attachments for events in salesforce [duplicate]

Hi can anyone please help me with a test class for below two methods global static void insertAttachment(string eventid, Map<String, Object> json_body) { try { Map&...
2 votes
1 answer
465 views

How to use Cobertura and JUnit reporters with LWC Jest?

When creating a new SFDX project, the default Jest configuration for LWC unit tests looks like this: jest.config.js const { jestConfig } = require('@salesforce/sfdx-lwc-jest/config'); module.exports =...
0 votes
1 answer
22 views

Test Code Coverage for Querying

I'm having some problems trying to write a test class. The issue is, the class which is being tested is composed of 5 methods that receive some information and use that information for querying. They'...
0 votes
0 answers
30 views

Does journey builder support emails with default commercial and transactional emails?

We have created a journey canvas that includes emails Email 1 - Default Commercial Email 2 - Default Transactional Email 3 - Default Commercial Email 4 - Default Transactional Email 5 - Default ...
  • 129
0 votes
0 answers
44 views

System.runAs() does not function as expected

static testMethod void testForDeletePrevent(){ PCA_Settings__c pcaConfig = TestDataFactory.createPcaSettings(); Common_Settings__c config = TestDataFactory.createCommonSettings(); ...
1 vote
1 answer
50 views

Testing a Field Sync utility without creating custom fields

I've created a utility in Apex that syncs a Lookup(User) field on Account or Opportunity with a specified Account or Opportunity Team Member Role, based on a custom metadata configuration. It's all ...
  • 1,079
0 votes
1 answer
236 views

How do I write test class for an OpportunityContactRole that has a loockup field for contacts?

the situation is as follows, I have the opportunity, and inside it I have the Contact Roles and inside the contacts roles I have a lookup field that points out contacts, my test coverage is at 97% but,...
  • 265
2 votes
1 answer
542 views

test class OrderSummary

Hi I am creating a test in which I have to insert an OrderSummary, I have tried many ways but I can't find a solution. In this post the same thing has happened but there is no solution posted. Code ...
  • 43
0 votes
1 answer
37 views

Test Class in Auto-populate

Hi can you help me build my Test Class? Below are my Apex Class and Test Class. Apex Class public void autoPopulate(List<SObject> newList){ System.debug('#####alignTaskSubCategory'); ...
1 vote
0 answers
40 views

How to handle namespace for Test.loadData method

I am trying to insert test data with Test.loadData for custom object with fields in my managed package. The problem is my developer org do not have a namespace and packaging org has it. How we can ...
-3 votes
1 answer
470 views

Test Apex class that has void as the return type

How to test an apex class that does not have a return value? Here this is the test class I wrote so far. It creates two content documents and then a case, what I am testing is linking the content ...
0 votes
1 answer
1k views

Cypress as UI test automation tool for Salesforce [closed]

Does anyone have experience using Cypress as a UI test automation tool for a Salesforce based project? If so, what are the drawbacks, constraints or implications, e.g. regarding login or possible ...
1 vote
3 answers
458 views

@testSetup best practice

I'm trying to understand something so I can use @testSetup annotation wisely. As i read here: https://developer.salesforce.com/docs/atlas.en-us.202.0.apexcode.meta/apexcode/...
  • 45
3 votes
1 answer
114 views

Flaky apex tests fail unreproducible with UNABLE_TO_LOCK_ROW when inserting Product2

Recently, our tests started to fail randomly with the dreaded UNABLE_TO_LOCK_ROW. The only fix seems to "Restart on Failed" the pipeline until it succeeds. This is the fixture code in ...
  • 1,400
0 votes
1 answer
74 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
2 answers
542 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 ...
  • 21
0 votes
0 answers
53 views

Query in Batch Apex returns "List has no rows for assignment to SObject" [duplicate]

I have test class where I am using a csv file to insert 200 records Account data. First 100 are like: remaining 100 are like: I am using above created test class to test a batch apex class which has ...
  • 401
0 votes
1 answer
648 views

Cannot insert a quotelineitem in my Test Class

I try to insert a quotelineitem in my test class but it fails with this error ,Please help me to resolve this issue . See below my code used in the test class Quote quote = new Quote(Name = 'devis1' ,...
0 votes
2 answers
999 views

Test Coverage for trigger on ActionCadeneSteptracker CDC

We are working on Updating Lead status on meaningful connect of call in HVS (High Velocity Sales), so we went ahead with the proposed solution of creating CDC on ActionCadenceStepTracker object. https:...
0 votes
2 answers
127 views

How to test Job states for a Apex Test with CronTrigger being read only?

I have the following function in a class that implements System.Schedulable: @TestVisible private void rescheduleJob(CronTrigger me, ISchedulable item, MySchedulableContext myCtx) { if (me....
  • 481
0 votes
0 answers
165 views

How Do You Test Multi-Currency Logic?

You cannot setup any currency during apex tests, and therefore any logic that works on the currency of records is untestable. Am I correct? The CurrencyType does not support DML (https://developer....
  • 1,400
0 votes
1 answer
285 views

Setup and NonSetup object insertion in Test Class

we've a factory class method to create sObject: Class: DataFactory: public static SObject createSObject(SObject sObj, String defaultClassName, Boolean doInsert) { SObject retObject = ...
0 votes
0 answers
64 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
1 answer
306 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 ...
  • 15
0 votes
0 answers
35 views

How can I get a list of fields that I added to one form in Salesforce?

I'm pretty new to Salesforce and I'm wondering if there is a way to get all the fields and HTML elements that I'm using with those forms to do some future testing with cypress and selenium. Does ...
  • 101
-1 votes
2 answers
220 views

What is test class for below code? [duplicate]

public class UtilityClass { public static String getDescribedObjects( List lstSObjectType ) { // Globally desribe all the objects Map<String, SObjectType> globalDescribe = Schema....
1 vote
1 answer
85 views

Test Class Id Error

I trying to get better and have built a trigger/test class using my knowledge I have learned however I am running into an error with the test class that for some reason I just cannot resolve and ...
1 vote
1 answer
281 views

Mocking Object list issue

This question is sort of a continuation to this question. I have this method: public static void sendMail(List<Object> selectedRows) { if (selectedRows.size() > 0) { for (...
1 vote
1 answer
1k views

how to mock Object list in a test class?

This is a method in my apex controller class: @AuraEnabled public static void sendMail(List<Object> selectedRows) { if (selectedRows.size() > 0) { for (Object obj : ...
0 votes
1 answer
120 views

No code coverage in sandbox and partial sandbox before preparing changeset

we have developed one solution in Salesforce in the developer sandbox the solution contains the Apex Class,Trigger, Custom Objet and LWC. Eventually, We are planning to release this solution as a ...
  • 205
1 vote
3 answers
399 views

Is it really needed to check whether a list has a record in a test class?

I have a scenario like this, I have created Opportunities in a Test setup and tried to access it in a test method to clone that record like, testSetup { // Create a list of Opportunity Records. ...
0 votes
0 answers
115 views

SOQL EventRelation is Test Class

The issue with SOQL on EventRelation filtered by Relation.Type is working as expected during normal execution. However, while executing the following LOC in test class it causes failure. Code: List<...
0 votes
1 answer
480 views

@InvocableVariables in Apex test class

I am having difficulty writing tests for the apex class. This is my first time working with apex classes and I don't understand how to send to @InvocableVariable. I've read answers to similar ...
0 votes
2 answers
211 views

Reference Ids of inserted in testsetup records

@isTest public with sharing class TestClass { public static Id userId; @TestSetup static void makeData(){ User u = createUser('userLastName'); insert u; userId = u....
  • 1,031
0 votes
2 answers
3k views

apex test public void - Non static method cannot be referenced from a static context

I have an apex class named votingRelationHandler. It is called from a trigger and works great but I am having issues with writing the test class. Issue in the Test Class: Non static method ...
  • 251
0 votes
0 answers
277 views

RecordType using Test.loadData in Testclass for account object

I am trying to export data in csv from one sandbox and trying to load the same data into Test class using loadData method. Currently , I am struggling in creating RecordType within Test class For ...
  • 205
0 votes
1 answer
534 views

Reporting on Advanced Content A/B Test blocks

I've set up some content items in Content Builder that use an A/B test content block. I'm testing two different images. How can I report on the performance of emails that use image A vs image B? Can ...
-1 votes
1 answer
727 views

Add a picklist value to Global Value Set in test class

I am working on test class that inserts an Opportunity with the opportunity products using the correct price book/price book entry. The OpportunityLineItem has a ProductSelected__c picklist field. We ...
4 votes
2 answers
3k views

How to use Stub API in the following scenario?

I am trying to understand Stub API a bit: My Class: public class DistributedMSelector { public static Map<string, user> getUserMap(Set<String> employeeIdSet){ Map<String,...
  • 481
3 votes
1 answer
2k views

In test class can see all org users in list

I have written one query in test class for fetching users,as per my understanding query should return the user records created in test class only,but its giving all user from salesforce org.is that ...
2 votes
0 answers
118 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
1 answer
83 views

How to create records for Person Account related to another Person Account

All I want to make @TestSetup Method to make coverage for my trigger. I need to make two Person Account and one is related to another. My code like below: // Person Account Setup String ...
0 votes
2 answers
898 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
0 votes
1 answer
162 views

How to cover piece of code using test class which is checking if its sandbox or Production

I have below Peice of code which is chekcing if its sandbox then run If part else run Else part if(runningInASandbox()) { return getSsoRedirect('one', startUrl, ...
  • 1